Skip to content

Options

draggable

TypeDefault
String''

Specifies which items inside the element should be draggable

js
new Sortable(document.getElementById('group'), {
  // draggable: 'li', // use tagName
  // draggable: '#item', // use id
  // draggable: '>div', // use css selector
  draggable: '.item', // use class
});

handle

TypeDefault
String | Function''

Drag handle selector within list items

js
new Sortable(document.getElementById('group'), {
  // handle: 'I', // use tagName
  // handle: '#handle', // use id
  // handle: (e) => e.target.tagName === 'I' ? true : false, // use function
  handle: '.handle', // use class
});

group

TypeDefault
String | Object''

To drag elements from one list into another, both lists must have the same group value.

js
// string
group: 'name',

// object
group: {
  name: 'group', // group name

  // whether elements can be added from other lists,
  // or an array of group names from which elements can be taken.
  put: true | false | ['group1', 'group2'],

  // whether elements can be moved out of this list.
  pull: true | false | 'clone',

  // revert drag element to initial position after moving to a another list.
  revertDrag: true | false,
}

lockAxis

TypeDefault
'x' | 'y'''

Axis on which dragging will be locked

sortable

TypeDefault
Booleantrue

Whether the current list can be sorted by dragging

disabled

TypeDefault
Booleanfalse

Disables the sortable if set to true

store

TypeDefault
anynull

store any data

js
sortable.option('store', value); // store value
sortable.option('store'); // get the stored value

autoScroll

TypeDefault
Booleantrue

Automatic scrolling when moving to the edge of the container

scrollThreshold

TypeDefault
Number55

Threshold to trigger autoScroll

scrollSpeed

TypeDefault
Object{ x: 10, y: 10 }

Threshold to trigger autoScroll

delay

TypeDefault
Number0

Time in milliseconds to define when the drag should start

delayOnTouchOnly

TypeDefault
Booleanfalse

Only delay if user is using touch

direction

TypeDefault
String''

Direction of Sortable, will be detected automatically if not given

easing

TypeDefault
String''

Easing for animation. See https://easings.net/ for examples.

For other possible values, see https://www.w3schools.com/cssref/css3_pr_animation-timing-function.asp

animation

TypeDefault
Number150

ms, animation speed moving items when sorting, 0 — without animation.

chosenClass

TypeDefault
String''

Class name for the chosen item

placeholderClass

TypeDefault
String''

Class name for the drop placeholder

ghostClass

TypeDefault
String''

The class of the mask element when dragging

multiple

TypeDefault
Booleanfalse

Enable multiple drag

selectHandle

TypeDefault
String | Functionfalse

Handle selector within list items which used to select element in multiple: true

js
new Sortable(document.getElementById('group'), {
  multiple: true,
  // selectHandle: 'Checkbox', // use tagName
  // selectHandle: '#checkbox', // use id
  // selectHandle: (e) => e.target.tagName === 'Checkbox' ? true : false, // use function
  selectHandle: '.checkbox', // use class
});

selectedClass

TypeDefault
String''

The class of the element when it is selected, it is usually used when multiple drag

touchStartThreshold

TypeDefault
Number1

How many pixels the point should move before cancelling a delayed drag event.

emptyInsertThreshold

TypeDefault
Number-1

Distance mouse must be from empty sortable to insert drag element into it

fallbackOnBody

TypeDefault
Booleanfalse

Appends the ghost element into the document's body

swapOnDrop

TypeDefault
Booleantrue

Whether to place the dragEl in the drop position after the drag is complete.

When the value is false, the dragEl will not move to the drop position (for virtual-list).

removeCloneOnDrop

TypeDefault
Booleantrue

Whether to remove the cloneEl after the drag is complete

customGhost

TypeDefault
Functionundefined

Customize the ghost element in drag

js
new Sortable(element, {
  customGhost: (nodes) => {
    // you must return an HTMLElement

    // example:
    const div = document.createElement('div');
    return div;
  },
});

Released under the MIT License.