Interactive demos of hcg-sortable, a lightweight zero-dependency JavaScript
library for reorderable lists, rows, and grids. Try axis modes, connected lists,
drag handles, custom placeholders, auto-scroll, and instance methods.
Version .
Full documentation
Default vertical sorting. All lifecycle callbacks fire into the event log at the bottom.
new HcgSortable('#list-y', {
axis: 'y',
placeholder: true,
animation: 150,
onUpdate(d) { console.log(d.oldIndex, '->', d.newIndex); }
});
Set axis: 'x' to sort items in a horizontal row.
new HcgSortable('#list-x', {
axis: 'x',
placeholder: true,
animation: 150
});
Use axis: 'grid' for two-dimensional grid layouts.
new HcgSortable('#list-grid', {
axis: 'grid',
placeholder: true,
animation: 150
});
With axis: 'auto', the library detects layout direction. This flex row resolves to horizontal.
new HcgSortable('#list-auto', {
axis: 'auto',
placeholder: true,
animation: 150
});
handle: '.handle' starts the drag; the button is in filter and never drags.
new HcgSortable('#list-handle', {
axis: 'y',
handle: '.handle',
filter: '.no-drag'
});
Drag items between lists that share group: 'shared'.
var opts = {
axis: 'y',
animation: 150,
group: { name: 'shared', pull: true, put: true }
};
new HcgSortable('#conn-a', opts);
new HcgSortable('#conn-b', opts);
Custom placeholder HTML, animation: 250, dragThreshold: 8, and a custom className.
new HcgSortable('#list-custom', {
axis: 'y',
placeholder: '<li class="item ghost-custom">drop here</li>',
className: 'dragging-custom',
animation: 250,
dragThreshold: 8
});
scroll, scrollSpeed, scrollThreshold, and containment keep dragging inside a scrollable box.
new HcgSortable('#list-scroll', {
axis: 'y',
scroll: true,
scrollSpeed: 14,
scrollThreshold: 36,
containment: document.getElementById('list-scroll')
});
Exercise option(), enable(), disable(), and destroy() on a live instance.
var api = new HcgSortable('#list-api', { axis: 'y', animation: 150 });
api.disable();
api.enable();
api.option('animation'); // get
api.setOption('animation', 250); // set
api.destroy();
Lifecycle callbacks from every demo above are logged here in real time.