Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

Get item list with parent

Open reimax opened this issue 4 years ago • 2 comments

I'm trying to get a list of all the items after sorting, along with their parents. How to do it? my code:

document.querySelectorAll( '.dd-list' ).forEach( element => {
        new Sortable(element, {
            group: 'nested',
            dataIdAttr: 'data-id',
            animation: 150,
            fallbackOnBody: true,
            swapThreshold: 0.65,
            handle: '.dd3-handle', // handle's class
            draggable: ".dd-item",
            store: {
                get: function (sortable) {
                    var order = localStorage.getItem(sortable.options.group);
                    return order ? order.split('|') : [];
                },
                set: function (sortable) {
                    var order = sortable.toArray();
                    console.log(order);  
                    // (6) ["41", "42", "44", "43", "45", "46"] - and no child...
                }
            },
            onEnd: function (evt) {

    
            }
        });
    });

reimax avatar Aug 31 '21 08:08 reimax

I need this same condition, get list array after update drag and drop in nested

ddevsr avatar Mar 21 '22 09:03 ddevsr

group: {
                    name: 'nested',
                    pull: function (to, from) {
                        var toLvl = 0;
                        var el = to.el;
                        for (var i = 0; el.parentNode; i++, el = el.parentNode) {
                            if(el.parentNode.classList && el.parentNode.classList.contains("dd-list")) {
                                toLvl++;
                            }
                        }

                        if(toLvl > checklist_maxDepth) {
                            return false;
                        }
                        return true;
                    },
                },

reimax avatar Mar 23 '22 05:03 reimax

Here is what I use:

    // Changed sorting within list
    onUpdate: function (evt) {
      let listId, listOrder, data;

      listId = evt.to.parentNode.getAttribute("data-id");
      listOrder = this.toArray(evt.to);
    },

    // Element is dropped into the list from another list
    onAdd: function (evt) {
      let itemId, newParentId, oldListOrder, newListOrder;

      itemId = evt.item.getAttribute("data-id");
      oldParentId = evt.from.parentNode.getAttribute("data-id");
      newParentId = evt.to.parentNode.getAttribute("data-id");

      oldListOrder = this.toArray(evt.from);
      newListOrder = this.toArray(evt.to);
    }

ivanBell199 avatar Jun 09 '23 23:06 ivanBell199