BetaBeta
Creates 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_StaticgetBeta
Gets the Sortable instance associated with a given element
The DOM element to look up
The Sortable instance, or undefined if none found
StaticmountBeta
Mount (register) a plugin globally so it can be used by any Sortable instance
A SortablePlugin instance, or an array of plugins
StaticclosestBeta
Finds the closest Sortable instance to a given element
The element to start searching from
Optionalselector: string
Optional CSS selector to filter parent elements
The closest Sortable instance, or null if none found
Beta
Set the cursor shown for the rest of the current drag, or clear it with
null. Cleared automatically when the drag ends.
A CSS cursor keyword, or null to restore the default
Use it to signal what a drop will do when only the consumer knows — a transfer that copies rather than moves, or a region that will reject the drop. CSS alone cannot do this: mid-drag the cursor is drawn from the pointer-capture target, not from whatever sits under the pointer.
On a native drag (nativeDrag) the browser owns the cursor and reads it
from dropEffect, so only copy, move, link / alias and
none / no-drop / not-allowed have any effect there.
Beta
Destroys the Sortable instance and removes all event listeners
Beta
Gets 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']
Beta
Sorts 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)
Beta
Save 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