sortable icon indicating copy to clipboard operation
sortable copied to clipboard

There is a way to get only the dropped item's attributes?

Open klesou opened this issue 3 years ago • 2 comments

When working with a lot of items in a sortable, I think that will require a lot of request in the database. So I was trying to find a way to get only the dropped item's attribute. Or a way to identify only the group that the item was dropped.

There is a way?

Thks!

klesou avatar May 28 '21 15:05 klesou

Looking for the same! Could you figure out a way in the meantime? I was also thinking if there is a way to identify the dropped item in the Livewire component itself? Any ideas?

maxwoerner avatar Nov 15 '21 19:11 maxwoerner

I modified the plugin method to pass in the event data to the livewire method

window.livewire.directive("sortable", (e, t, n) => {
            if (t.modifiers.length > 0) return;
            let o = { draggable: "[wire\\:sortable\\.item]" };
            e.querySelector("[wire\\:sortable\\.handle]") && (o.handle = "[wire\\:sortable\\.handle]"),
                new r(e, o).on("sortable:stop", (sortableEvent) => {
                    let sortableData = {
                        'id' : sortableEvent.dragEvent.originalSource.id,
                        'newIndex' : sortableEvent.newIndex,
                        'oldIndex' : sortableEvent.oldIndex,
                    };
                    setTimeout(() => {
                        let r = [];
                        e.querySelectorAll("[wire\\:sortable\\.item]").forEach((e, t) => {
                            r.push({ order: t + 1, value: e.getAttribute("wire:sortable.item") });
                        }),
                            n.call(t.method, r, sortableData);
                    }, 1);
                });
        });

tushargugnani avatar Mar 21 '22 18:03 tushargugnani

You can now get information on the Groups updated and Filter only Updated groups to make the whole process easier

Refer to my post https://github.com/livewire/sortable/issues/58

markusyesloop avatar Dec 11 '22 07:12 markusyesloop