Repository navigation
Moving between lists that share data #2358
|
We have a product that needs a simple way to manual reorder items in a list that can have 100+ items. I have gotten pretty close to this, but still have some issues that would have to be fixed.
I have created a simple vue3 codesandbox with a demo: https://codesandbox.io/p/github/codetakki/sort-same-list-poc/ |
Replies: 1 comment 2 replies
|
To hide the original item being moved so that only the dragged preview (or drag clone) is visible during transit between linked lists, you can configure Sortable's built-in CSS class hooks: Solution:When SortableJS begins a drag, it applies import Sortable from 'sortablejs';
const options = {
group: 'shared-data-list',
animation: 150,
ghostClass: 'sortable-hidden-ghost',
chosenClass: 'sortable-hidden-chosen',
forceFallback: true, // Optional: ensures consistent preview rendering
fallbackClass: 'sortable-drag-preview'
};
new Sortable(document.getElementById('list-left'), options);
new Sortable(document.getElementById('list-right'), options);Accompanying CSS:/* Hides the placeholder left in the list while dragging */
.sortable-hidden-ghost {
opacity: 0 !important;
visibility: hidden !important;
height: 0 !important;
padding: 0 !important;
margin: 0 !important;
border: none !important;
}
/* Hides the original row if not using fallback */
.sortable-hidden-chosen {
opacity: 0 !important;
}
/* Style the floating preview item */
.sortable-drag-preview {
opacity: 0.9;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
z-index: 9999;
}Setting |
To hide the original item being moved so that only the dragged preview (or drag clone) is visible during transit between linked lists, you can configure Sortable's built-in CSS class hooks:
Solution:
When SortableJS begins a drag, it applies
ghostClassto the placeholder left in the original list andchosenClassto the selected item.