Sortable — is a JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices.
/*
:: Vendor Path
node_modules/sortablejs/
:: Installed
npm install sortablejs
:: SOW Controller Init
*/ $.SOW.vendor.sortable.init('.sortable');
/*
:: Plugin Options|Defaults
*/ $.SOW.vendor.sortable.init('.sortable', {
dataIdAttr: 'data-id', // used by ajax (as item/database id)
handle: '.sortable-handle',
animation: 150,
ghostClass: 'bg-primary-soft',
chosenClass: 'bg-white-alt',
swapClass: 'bg-warning-soft',
filter: '.js-ignore', // 'filtered' class is not draggable
headers: '', // jQuery ajax POST request headers (optional)
crossDomain: '', // jQuery ajax POST request crossDomain (optional)
});
<!--
Static, doing nothing comparing to Ajax.
Might be used inside a form with hidden inputs and
updated when user click "Submit" button!
data-sort-disable="true" - disable sorting by param
-->
<div class="list-group sortable">
<div class="list-group-item">Item 1</div>
<div class="list-group-item">Item 2</div>
<div class="list-group-item js-ignore">Disabled</div>
<div class="list-group-item">Item 4</div>
<div class="list-group-item">Item 5</div>
<div class="list-group-item">Item 6</div>
</div>
<!--
data-sort-swap="true" - enable swapping effect
-->
<div class="list-group sortable" data-sort-swap="true">
<div class="list-group-item">Item 1</div>
<div class="list-group-item">Item 2</div>
<div class="list-group-item">Item 3</div>
<div class="list-group-item">Item 4</div>
<div class="list-group-item">Item 5</div>
<div class="list-group-item">Item 6</div>
</div>
<div class="list-group sortable">
<div class="list-group-item">
<span class="sortable-handle fi fi-list float-start"></span>
Item 1
</div>
<div class="list-group-item">
<span class="sortable-handle fi fi-list float-start"></span>
Item 2
</div>
<div class="list-group-item js-ignore">
<span class="sortable-handle fi fi-list float-start"></span>
Disabled
</div>
<div class="list-group-item">
<span class="sortable-handle fi fi-list float-start"></span>
Item 4
</div>
<div class="list-group-item">
<span class="sortable-handle fi fi-list float-start"></span>
Item 5
</div>
<div class="list-group-item">
<span class="sortable-handle fi fi-list float-start"></span>
Item 6
</div>
</div>
<!--
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NOTE: Ajax requests are sent using 'POST' type and cannot be changed!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Turn any .sortable to ajax by adding:
data-ajax-update-url="../demo.files/php/demo.ajax_request.php"
data-ajax-update-identifier="client_list"
data-update-toast-success="Order Saved!"
data-update-toast-position="bottom-center"
data-id="..." usually database item id
data-update-ajax-identifier="..." backend identifier to know what to update
* data-ajax-update-params can be used instead.
multiple optional params/identifiers to send to your backend
data-ajax-update-params="['action','update']['param2','value2']"
Note: debug is turned on by sow.config.js - check your console for ajax request.
-->
<div class="list-group sortable"
data-ajax-update-url="../demo.files/php/demo.ajax_request.php"
data-ajax-update-identifier="client_list"
data-ajax-update-params="['action','update']['param2','value2']"
data-update-toast-success="Order Saved!"
data-update-toast-position="bottom-center">
<div data-id="1" class="list-group-item">Item 1</div>
<div data-id="2" class="list-group-item">Item 2</div>
<div data-id="3" class="list-group-item">Item 3</div>
<div data-id="4" class="list-group-item">Item 4</div>
<div data-id="5" class="list-group-item">Item 5</div>
<div data-id="6" class="list-group-item">Item 6</div>
</div>
<!--
To share multiple lists, add:
data-shared-group="..." must be all the same
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NOTE: Ajax requests are sent using 'POST' type and cannot be changed!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajax note: Each list should have its own ajax params:
data-ajax-update-url="../demo.files/php/demo.ajax_request.php"
data-ajax-update-identifier="client_list_1"
data-ajax-update-params="['action','update']['param2','value2']"
data-update-toast-success="Order Saved!"
data-update-toast-position="bottom-center"
And also, data-id="..." added to each item
-->
<!-- list 1 -->
<div class="list-group sortable" data-shared-group="client-list">
<div class="list-group-item">Item 1</div>
<div class="list-group-item">Item 2</div>
<div class="list-group-item">Item 3</div>
<div class="list-group-item">Item 4</div>
<div class="list-group-item">Item 5</div>
<div class="list-group-item">Item 6</div>
</div>
<!-- list 2 -->
<div class="list-group sortable" data-shared-group="client-list">
<div class="list-group-item">Item 1</div>
<div class="list-group-item">Item 2</div>
<div class="list-group-item">Item 3</div>
<div class="list-group-item">Item 4</div>
<div class="list-group-item">Item 5</div>
<div class="list-group-item">Item 6</div>
</div>
<!--
Two params are required:
data-shared-group="..."
data-pull-mode="clone"
data-put-denied="true" - do not allow to clone into this list (default: false)
data-sort-disable="true" - disable sorting for this list (default: false)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NOTE: Ajax requests are sent using 'POST' type and cannot be changed!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajax note: Each list should have its own ajax params:
data-ajax-update-url="../demo.files/php/demo.ajax_request.php"
data-ajax-update-identifier="client_list_1"
data-ajax-update-params="['action','update']['param2','value2']"
data-update-toast-success="Order Saved!"
data-update-toast-position="bottom-center"
And also, data-id="..." added to each item
-->
<!-- list 1 -->
<div class="list-group sortable" data-shared-group="client-list2" data-pull-mode="clone">
<div class="list-group-item">Item 1</div>
<div class="list-group-item">Item 2</div>
<div class="list-group-item">Item 3</div>
<div class="list-group-item">Item 4</div>
<div class="list-group-item">Item 5</div>
<div class="list-group-item">Item 6</div>
</div>
<!-- list 2 -->
<div class="list-group sortable" data-shared-group="client-list2" data-pull-mode="clone">
<div class="list-group-item">Item 1</div>
<div class="list-group-item">Item 2</div>
<div class="list-group-item">Item 3</div>
<div class="list-group-item">Item 4</div>
<div class="list-group-item">Item 5</div>
<div class="list-group-item">Item 6</div>
</div>
<div class="sortable">
<div class="w--120 h--120 shadow-md border rounded p-2 m-2 d-inline-block">Item 1</div>
<div class="w--120 h--120 shadow-md border rounded p-2 m-2 d-inline-block">Item 2</div>
<div class="w--120 h--120 shadow-md border rounded p-2 m-2 d-inline-block">Item 3</div>
<div class="w--120 h--120 shadow-md border rounded p-2 m-2 d-inline-block">Item 4</div>
<div class="w--120 h--120 shadow-md border rounded p-2 m-2 d-inline-block">Item 5</div>
<div class="w--120 h--120 shadow-md border rounded p-2 m-2 d-inline-block">Item 6</div>
</div>
<!--
Note: cannot drag Item 1.3 inside Item 1.2
because Item 1.2 missing .sortable class and data-sortable-type="nested"
Ajax Note:
Ajax params must be added to each .sortable
Ajax request is sent for the changed .sortable, not for all at once!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NOTE: Ajax requests are sent using 'POST' type and cannot be changed!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
data-ajax-update-url="../demo.files/php/demo.ajax_request.php"
data-ajax-update-identifier="category_1"
data-ajax-update-params="['action','update']['param2','value2']"
data-update-toast-success="Order Saved!"
data-update-toast-position="bottom-center"
data-sortable-type="nested" required to each .sortable
-->
<div class="list-group sortable" data-sortable-type="nested">
<div class="list-group-item">Item 1.1
<div class="list-group sortable" data-sortable-type="nested">
<div class="list-group-item" style="">Item 2.2
<div class="list-group sortable" data-sortable-type="nested">
<div class="list-group-item">Item 3.2</div>
<div class="list-group-item">Item 2.1</div>
<div class="list-group-item">Item 3.1</div>
<div class="list-group-item">Item 3.3</div>
<div class="list-group-item">Item 3.4</div>
</div>
</div>
<div class="list-group-item">Item 2.3</div>
<div class="list-group-item">Item 2.4</div>
</div>
</div>
<div class="list-group-item">Item 1.2</div>
<div class="list-group-item">Item 1.3</div>
<div class="list-group-item">Item 1.4
<div class="list-group sortable" data-sortable-type="nested">
<div class="list-group-item">Item 2.1</div>
<div class="list-group-item">Item 2.2</div>
<div class="list-group-item">Item 2.3</div>
<div class="list-group-item">Item 2.4</div>
</div>
</div>
<div class="list-group-item">Item 1.5</div>
</div>