BetaBetaCreates a new Sortable instance
The DOM element to make sortable
Configuration options for the sortable behavior
SortableError When the provided element is invalid or options are malformed
Static BetaactiveThe currently active Sortable instance (if any drag is in progress)
Static BetadraggedThe currently dragged element (if any)
Static BetaghostThe ghost element shown during drag (if any)
Static BetacloneThe cloned element during clone operations (if any)
Static BetautilsUtility functions for DOM operations
Add an event listener and return an unsubscribe function
Remove a previously-registered event listener (symmetric to on)
Get the index of an element within its parent
Insert an element at a specific index within a parent
Find the nearest ancestor matching selector, optionally bounded by ctx
Toggle a CSS class on an element; pass force to set explicitly
Deep-clone an element (cloneNode(true))
Readonly BetaelementThe DOM element that this Sortable instance is bound to
Readonly BetaoptionsCurrent configuration options for this Sortable instance
Readonly BetadropBetadragReadonly BetaeventOptional Beta_Optional Beta_Optional Beta_Optional Beta_StaticgetBetaGets the Sortable instance associated with a given element
The DOM element to look up
The Sortable instance, or undefined if none found
StaticmountBetaMount (register) a plugin globally so it can be used by any Sortable instance
A SortablePlugin instance, or an array of plugins
StaticclosestBetaFinds the closest Sortable instance to a given element
The element to start searching from
Optionalselector: stringOptional CSS selector to filter parent elements
The closest Sortable instance, or null if none found
BetaDestroys the Sortable instance and removes all event listeners
BetaGets the current order of elements as an array of data-id attributes
Array of string IDs representing the current order
This method reads the data-id attribute from each sortable item.
If an item doesn't have a data-id attribute, its index will be used.
The attribute name can be customized using the dataIdAttr option.
const sortable = new Sortable(element);
const order = sortable.toArray();
console.log('Current order:', order); // ['item-1', 'item-2', 'item-3']
BetaSorts the elements according to the given order of data-id values
Array of data-id values representing the desired order
Whether to animate the reorder (default: true)
BetaSave the current sort order using the configured store
Calls the store.set callback with this Sortable instance if configured.
This allows persisting sort order to localStorage, a database, etc.
const sortable = new Sortable(element, {
store: {
get: (sortable) => {
const stored = localStorage.getItem('sort-order');
return stored ? JSON.parse(stored) : [];
},
set: (sortable) => {
localStorage.setItem('sort-order', JSON.stringify(sortable.toArray()));
}
}
});
// Later, manually trigger a save
sortable.save();
Beta
Main Sortable class for creating drag-and-drop sortable lists
Remarks
This is the main entry point for the Resortable library. It provides a modern, TypeScript-first approach to creating sortable drag-and-drop interfaces.
Unlike the original Sortable.js, this version:
Example: Creating a basic sortable list
Public