Move list item in list array item to top laravel năm 2024

You can use any element for the list and its elements, not just

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

3/

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

4. Here is an example with

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

5s.


Options

var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });


// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

6 option

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

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

6 value. You can also define whether lists can give away, give and keep a copy (

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

8), and receive elements.

  • name: // Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js'; 9 — group name
  • pull: // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 0 — ability to move from the list. // Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js'; 8 — copy the item, rather than move. Or an array of group names which the elements may be put in. Defaults to // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 2.
  • put: // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 3 — whether elements can be added from other lists, or an array of group names from which elements can be added.
  • revertClone: // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 4 — revert cloned element to initial position after moving to a another list.

Demo:

  • https://jsbin.com/hijetos/edit?js,output
  • https://jsbin.com/nacoyah/edit?js,output — use of complex logic in the // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 5 and // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 6
  • https://jsbin.com/bifuyab/edit?js,output — use // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 7

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

8 option

Allow sorting inside list.

Demo: https://jsbin.com/jayedig/edit?js,output


// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

9 option

Time in milliseconds to define when the sorting should start. Unfortunately, due to browser restrictions, delaying is not possible on IE or Edge with native drag & drop.

Demo: https://jsbin.com/zosiwah/edit?js,output


<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

0 option

Whether or not the delay should be applied only if the user is using touch (eg. on a mobile device). No delay will be applied in any other case. Defaults to

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

1.


<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

2 option

Percentage of the target that the swap zone will take up, as a float between

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

3 and

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

4.

Demo:


<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

5 option

Set to

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

2 to set the swap zone to the sides of the target, for the effect of sorting "in between" items.

Demo:


<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

7 option

Percentage of the target that the inverted swap zone will take up, as a float between

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

3 and

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

4. If not given, will default to

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

2.


var el = document.getElementById('items'); var sortable = Sortable.create(el);

1 option

Direction that the Sortable should sort in. Can be set to

var el = document.getElementById('items'); var sortable = Sortable.create(el);

2,

var el = document.getElementById('items'); var sortable = Sortable.create(el);

3, or a function, which will be called whenever a target is dragged over. Must return

var el = document.getElementById('items'); var sortable = Sortable.create(el);

2 or

var el = document.getElementById('items'); var sortable = Sortable.create(el);

3.

Example of direction detection for vertical list that includes full column and half column elements:

Sortable.create(el, { direction: function(evt, target, dragEl) {

if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  return 'horizontal';
}
return 'vertical';
} });


var el = document.getElementById('items'); var sortable = Sortable.create(el);

6 option

This option is similar to

var el = document.getElementById('items'); var sortable = Sortable.create(el);

7 option.

When the

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

9 option is set, some phones with very sensitive touch displays like the Samsung Galaxy S8 will fire unwanted touchmove events even when your finger is not moving, resulting in the sort not triggering.

This option sets the minimum pointer movement that must occur before the delayed sorting is cancelled.

Values between 3 to 5 are good.


var el = document.getElementById('items'); var sortable = Sortable.create(el);

9 options

Disables the sortable if set to

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

2.

Demo: https://jsbin.com/sewokud/edit?js,output

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };


var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

1 option

To make list items draggable, Sortable disables text selection by the user. That's not always desirable. To allow text selection, define a drag handler, which is an area of every list element that allows it to be dragged around.

Demo: https://jsbin.com/numakuh/edit?html,js,output

Sortable.create(el, { handle: ".my-handle" });

bower install --save sortablejs

0

bower install --save sortablejs

1


var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

2 option

bower install --save sortablejs

2


var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

3 option

Class name for the drop placeholder (default

var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

4).

Demo: https://jsbin.com/henuyiw/edit?css,js,output

bower install --save sortablejs

3


var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

5 option

Class name for the chosen item (default

var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

6).

Demo: https://jsbin.com/hoqufox/edit?css,js,output

bower install --save sortablejs

4

bower install --save sortablejs

5


var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

7 option

If set to

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

2, the Fallback for non HTML5 Browser will be used, even if we are using an HTML5 Browser. This gives us the possibility to test the behaviour for older Browsers even in newer Browser, or make the Drag 'n Drop feel more consistent between Desktop , Mobile and old Browsers.

On top of that, the Fallback always generates a copy of that DOM Element and appends the class

var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start delayOnTouchOnly: false, // only delay if user is using touch touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, 0 — without animation easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples. handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call event.preventDefault() when triggered filter draggable: ".item", // Specifies which items inside the element should be draggable dataIdAttr: 'data-id', // HTML attribute that is used by the toArray() method ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item swapThreshold: 1, // Threshold of the swap zone invertSwap: false, // Will always use inverted swap zone if set to true invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default) direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given) forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. dragoverBubble: false, removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it setData: function (/ DataTransfer */dataTransfer, / HTMLElement*/dragEl) {

dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}, // Element is chosen onChoose: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element is unchosen onUnchoose: function(/*Event/evt) {
// same properties as onEnd
}, // Element dragging started onStart: function (/*Event/evt) {
evt.oldIndex;  // element index within parent
}, // Element dragging ended onEnd: function (/*Event/evt) {
var itemEl = evt.item;  // dragged HTMLElement
evt.to;    // target list
evt.from;  // previous list
evt.oldIndex;  // element's old index within old parent
evt.newIndex;  // element's new index within new parent
evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
evt.clone // the clone element
evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
}, // Element is dropped into the list from another list onAdd: function (/*Event/evt) {
// same properties as onEnd
}, // Changed sorting within list onUpdate: function (/*Event/evt) {
// same properties as onEnd
}, // Called by any change to the list (add / update / remove) onSort: function (/*Event/evt) {
// same properties as onEnd
}, // Element is removed from the list into another list onRemove: function (/*Event/evt) {
// same properties as onEnd
}, // Attempt to drag a filtered element onFilter: function (/*Event/evt) {
var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
}, // Event when you move an item in the list or between lists onMove: function (/*Event/evt, /*Event/originalEvent) {
// Example: https://jsbin.com/nawahef/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // DOMRect {left, top, right, bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // DOMRect
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
originalEvent.clientY; // mouse position
// return false; — for cancel
// return -1; — insert before target
// return 1; — insert after target
// return true; — keep default insertion point based on the direction
// return void; — keep default insertion point based on the direction
}, // Called when creating a clone of element onClone: function (/*Event/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}, // Called when dragging element changes position onChange: function(/*Event/evt) {
evt.newIndex // most likely why this event is used is to get the dragging element's current index
// same properties as onEnd
} });

9 defined in the options. This behaviour controls the look of this 'dragged' Element.

Demo: https://jsbin.com/sibiput/edit?html,css,js,output


var el = document.getElementById('items'); var sortable = Sortable.create(el);

7 option

Emulates the native drag threshold. Specify in pixels how far the mouse should move before it's considered as a drag. Useful if the items are also clickable like in a list of links.

When the user clicks inside a sortable element, it's not uncommon for your hand to move a little between the time you press and the time you release. Dragging only starts if you move the pointer past a certain tolerance, so that you don't accidentally start dragging every time you click.

3 to 5 are probably good values.


Sortable.create(el, { direction: function(evt, target, dragEl) {

if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  return 'horizontal';
}
return 'vertical';
} });

1 option

If set to

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

2, the dragover event will bubble to parent sortables. Works on both fallback and native dragover event. By default, it is false, but Sortable will only stop bubbling the event once the element has been inserted into a parent Sortable, or can be inserted into a parent Sortable, but isn't at that specific time (due to animation, etc).

Since 1.8.0, you will probably want to leave this option as false. Before 1.8.0, it may need to be

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

2 for nested sortables to work.


Sortable.create(el, { direction: function(evt, target, dragEl) {

if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  return 'horizontal';
}
return 'vertical';
} });

4 option

If set to

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

1, the clone is hidden by having it's CSS

Sortable.create(el, { direction: function(evt, target, dragEl) {

if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  return 'horizontal';
}
return 'vertical';
} });

6 property set to

Sortable.create(el, { direction: function(evt, target, dragEl) {

if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  return 'horizontal';
}
return 'vertical';
} });

7. By default, this option is

// Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll());

2, meaning Sortable will remove the cloned element from the DOM when it is supposed to be hidden.


Sortable.create(el, { direction: function(evt, target, dragEl) {

if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  return 'horizontal';
}
return 'vertical';
} });

9 option

The distance (in pixels) the mouse must be from an empty sortable while dragging for the drag element to be inserted into that sortable. Defaults to

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

0. Set to

<ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul>

3 to disable this feature.

Demo: https://jsbin.com/becavoj/edit?js,output

An alternative to this option would be to set a padding on your list when it is empty.

For example:

bower install --save sortablejs

6

Warning: For

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

2 to work, it must have no node inside (even text one).

Demo: https://jsbin.com/yunakeg/edit?html,css,js,output


Event object (demo)

  • to: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3 — list, in which moved element
  • from: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3 — previous list
  • item: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3 — dragged element
  • clone: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3
  • oldIndex: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 7 — old index within parent
  • newIndex: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 7 — new index within parent
  • oldDraggableIndex: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 7 — old index within parent, only counting draggable elements
  • newDraggableIndex: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 7 — new index within parent, only counting draggable elements
  • pullMode: Sortable.create(el, { handle: ".my-handle" }); 1 — Pull mode if dragging into another sortable ( Sortable.create(el, { handle: ".my-handle" }); 2, // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 2, or <ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> 1), otherwise undefined

Sortable.create(el, { handle: ".my-handle" });

5 event object

  • to: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3
  • from: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3
  • dragged: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3
  • draggedRect: Sortable.create(el, { handle: ".my-handle" }); 9
  • related: var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3 — element on which have guided
  • relatedRect: Sortable.create(el, { handle: ".my-handle" }); 9
  • willInsertAfter: bower install --save sortablejs 02 — // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); 2 if will element be inserted after target (or <ul id="items"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> 1 if before)

Methods

option(name:

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

9[, value:

bower install --save sortablejs

06]):

bower install --save sortablejs

06

Get or set the option.

closest(el:

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

3[, selector:

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

9]):

bower install --save sortablejs

10

For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

toArray():

bower install --save sortablejs

11

Serializes the sortable's item

bower install --save sortablejs

12's (

bower install --save sortablejs

13 option) into an array of string.

sort(order:

bower install --save sortablejs

11, useAnimation:

bower install --save sortablejs

02)

Sorts the elements according to the array.

bower install --save sortablejs

7

save()

Save the current sorting (see )

destroy()

Removes the sortable functionality completely.


Store

Saving and restoring of the sort.

bower install --save sortablejs

8

bower install --save sortablejs

9


Bootstrap

Demo: https://jsbin.com/visimub/edit?html,js,output

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

0


Static methods & properties

Sortable.create(el:

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

3[, options:

bower install --save sortablejs

17]):

bower install --save sortablejs

18

Create new instance.


Sortable.active:

bower install --save sortablejs

18

The active Sortable instance.


Sortable.dragged:

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

3

The element being dragged.


Sortable.ghost:

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

3

The ghost element.


Sortable.clone:

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

3

The clone element.


Sortable.get(element:

var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set };

3):

bower install --save sortablejs

18

Get the Sortable instance on an element.


Sortable.mount(plugin:

bower install --save sortablejs

25)

Mounts a plugin to Sortable.


Sortable.utils
  • on(el bower install --save sortablejs 26, event bower install --save sortablejs 27, fn bower install --save sortablejs
  • — attach an event handler function
  • off(el bower install --save sortablejs 26, event bower install --save sortablejs 27, fn bower install --save sortablejs
  • — remove an event handler
  • css(el bower install --save sortablejs
  • bower install --save sortablejs 33 — get the values of all the CSS properties
  • css(el bower install --save sortablejs 26, prop bower install --save sortablejs
  • bower install --save sortablejs 36 — get the value of style properties
  • css(el bower install --save sortablejs 26, prop bower install --save sortablejs 27, value bower install --save sortablejs
  • — set one CSS properties
  • css(el bower install --save sortablejs 26, props bower install --save sortablejs
  • — set more CSS properties
  • find(ctx bower install --save sortablejs 26, tagName bower install --save sortablejs 27[, iterator bower install --save sortablejs 28]) bower install --save sortablejs 45 — get elements by tag name
  • bind(ctx bower install --save sortablejs 36, fn bower install --save sortablejs
  • bower install --save sortablejs 28 — Takes a function and returns a new one that will always have a particular context
  • is(el bower install --save sortablejs 26, selector bower install --save sortablejs
  • bower install --save sortablejs 51 — check the current matched set of elements against a selector
  • closest(el bower install --save sortablejs 26, selector bower install --save sortablejs 27[, ctx bower install --save sortablejs 26]) bower install --save sortablejs 55 — for each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree
  • clone(el bower install --save sortablejs
  • bower install --save sortablejs 26 — create a deep copy of the set of matched elements
  • toggleClass(el bower install --save sortablejs 26, name bower install --save sortablejs 27, state bower install --save sortablejs
  • — add or remove one classes from each element
  • detectDirection(el bower install --save sortablejs
  • bower install --save sortablejs 27 — automatically detect the of the element as either var el = document.getElementById('items'); var sortable = Sortable.create(el); 2 or var el = document.getElementById('items'); var sortable = Sortable.create(el); 3
  • index(el bower install --save sortablejs 26, selector bower install --save sortablejs
  • bower install --save sortablejs 67 — index of the element within its parent for a selected set of elements
  • getChild(el bower install --save sortablejs 26, childNum bower install --save sortablejs 67, options bower install --save sortablejs 33, includeDragEl bower install --save sortablejs 51): var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; 3 — get the draggable element at a given index of draggable elements within a Sortable instance
  • expando bower install --save sortablejs 27 — expando property name for internal use, sortableListElement[expando] returns the Sortable instance of that elemenet

Plugins

Extra Plugins (included in complete versions)

  • MultiDrag
  • Swap

Default Plugins (included in default versions)

  • AutoScroll
  • OnSpill

CDN

// Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js';

1


Contributing (Issue/PR)

Please, read this.


Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

How do you move elements to the top of an array in PHP?

array_unshift() prepends passed elements to the front of the array . Note that the list of elements is prepended as a whole, so that the prepended elements stay in the same order. All numerical array keys will be modified to start counting from zero while literal keys won't be changed.nullarray_unshift - Manual - PHPwww.php.net › manual › function.array-unshift.phpnull

How do you add an item to the top of an array in PHP?

The array_unshift() function is used to add one or more elements at the beginning of the array.nullHow to insert an item at the beginning of an array in PHP ? - GeeksforGeekswww.geeksforgeeks.org › how-to-insert-an-item-at-the-beginning-of-an-ar...null

How do you move elements in an array?

To move an array element without an extra array, use array destructuring and swapping. Specify the indices to swap, and swap their values directly using destructuring assignment. This efficiently rearranges the array elements without creating a new array.nullHow to move an array element from one array position to another in ...www.geeksforgeeks.org › how-to-move-an-array-element-from-one-array-...null

How to change the position of an array element in PHP?

See Also.

array_unshift() - Prepend one or more elements to the beginning of an array..

array_push() - Push one or more elements onto the end of array..

array_pop() - Pop the element off the end of array..