SortableJS plugin to keep filtered elements pinned in place during drag-and-drop sorting
npm install sortablejs-pinnedSortableJS plugin that keeps certain elements fixed in place while others can be sorted around them.
Works with Livewire, Alpine, Vue (preserves comment nodes).
``bash`
npm install sortablejs-pinned
`javascript
import Sortable from 'sortablejs';
import Pinned from 'sortablejs-pinned';
Sortable.mount(Pinned());
new Sortable(document.getElementById('list'), {
pinned: true,
filter: '.pinned',
animation: 150,
});
`
CDN:
`html`
`html`
The .pinned element stays at index 1. Other items sort around it.
| Option | Type | Description |
|--------|------|-------------|
| pinned | boolean | Enable the plugin |filter
| | string | Selector for pinned elements |
- group option: Cross-list dragging not supported. Comment nodes won't follow elements between lists.
- Swap plugin: May conflict - not tested.
- MultiDrag` plugin: Should work, but not fully tested.
For Livewire/Alpine/Vue projects, use single-list only.
Records DOM structure at drag start, restores pinned elements after each move.
MIT