sortable-dnd
A JS Library for Drag and Drop, supports Sortable and Draggable
Usage
Install
npm install sortable-dnd
HTML
<ul id="group">
<li class="item">
<i id="handle" class="handle">handle</i>
<p>1</p>
</li>
<li class="item">
<i id="handle" class="handle">handle</i>
<p>2</p>
</li>
<li class="item">
<i id="handle" class="handle">handle</i>
<p>3</p>
</li>
</ul>
JavaScript
import Sortable from 'sortable-dnd';
let sortable = new Sortable(document.getElementById('group'), {
draggable: '.item',
handle: '.handle',
});
Options
new Sortable(element, {
draggable: '',
handle: '',
group: '',
lockAxis: '',
multiple: false,
selectHandle: '',
easing: '',
animation: 150,
chosenClass: '',
selectedClass: '',
placeholderClass: '',
ghostStyle: {},
ghostClass: '',
sortable: true,
disabled: false,
autoScroll: true,
scrollThreshold: 55,
scrollSpeed: { x: 10, y: 10 },
delay: 0,
delayOnTouchOnly: false,
touchStartThreshold: 1,
emptyInsertThreshold: -1,
fallbackOnBody: false,
store: null,
direction: '',
swapOnDrop: true,
customGhost: (nodes) => {
},
onChoose: (event) => {
},
onUnchoose: (event) => {
},
onDrag: (event) => {
},
onMove: (event) => {
},
onDrop: (event) => {
},
onAdd: (event) => {
},
onRemove: (event) => {
},
onChange: (event) => {
},
onSelect: (event) => {
},
onDeselect: (event) => {
},
});
Group
group: 'name',
group: {
name: 'group',
put: true | false | ['group1', 'group2'],
pull: true | false | 'clone',
revertDrag: true | false,
}
SortableEvent
event.from;
event.to;
event.node;
event.nodes;
event.clone;
event.clones;
event.target;
event.oldIndex;
event.newIndex;
event.event;
event.pullMode;
event.relative;
event.revertDrag;
event.backToOrigin;
SelectEvent
event.event;
event.index;
event.node;
event.from;
Methods
let sortable = new Sortable(el);
sortable.destroy();
sortable.option(key, value?);
sortable.select(element);
sortable.deselect(element);
sortable.getSelectedElements();
Static Methods & Properties
import Sortable from 'sortable-dnd';
Sortable.create(el: HTMLElement, options: SortableOptions);
Sortable.get(el: HTMLElement);
Sortable.dragged;
Sortable.clone;
Sortable.ghost;
Sortable.active;
Utils
import Sortable from 'sortable-dnd';
const { on, off, css, index, closest, getRect, toggleClass } = Sortable.utils;
on(el: HTMLElement, event: String, fn: Function);
off(el: HTMLElement, event: String, fn: Function);
css(el: HTMLElement, prop: String, value: String);
index(el: HTMLElement, selector: String);
closest(el: HTMLElement, selector: String, context: HTMLElement, includeContext: Boolean);
getRect(element: HTMLElement, relativeToContainingBlock: boolean, container: HTMLElement);
toggleClass(el: HTMLElement, name: String, state: Boolean);