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
  draggable: '>*',
});

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
  handle: '',
});

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',

  // whether to revert the drag element to its initial position after clone 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 you want.

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 }

Vertical & Horizontal scrolling speed (px)

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.

delay

TypeDefault
Number0

Time in milliseconds to define when the drag should start.

delayOnTouchOnly

TypeDefault
Booleanfalse

Only delay if user is using touch.

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.

appendToBody

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.

  • true : The dragEl will be placed in the drop position after the drag is complete.
  • false : The dragEl will not move to the drop position (used for virtual-list).

removeCloneOnDrop

TypeDefault
Booleantrue

Whether to remove the cloneEl after the drag is complete.

dropOnAnimationEnd

TypeDefault
Booleanfalse

Trigger the onDrop event when the animation 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;
  },
});

chosenClass

TypeDefault
String''

Class name for the chosen item.

placeholderClass

TypeDefault
String''

Class name for the drop placeholder.

ghostClass

TypeDefault
String''

Class name for the ghost element.

ghostStyle

TypeDefault
Object{}

Style object for the ghost element.

Released under the MIT License.