Sortable pattern.

November 2, 2023 ยท View on GitHub

A pattern to make listings sortable.

Configuration

OptionTypeDefaultDescription
selectorstring"li"Selector to use to draggable items in pattern.
dragClassstring"item-dragging"Class to apply to original item that is being dragged.
cloneClassstring"dragging"Class to apply to cloned item that is dragged.
dropfunction, string""Callback function or name of callback function in global namespace to be called when item is dropped.

Examples

Example 1

Default

  • One
  • Two
  • Three
<style type="text/css" media="screen">
    .item-dragging {
        background-color: red;
    }
    .dragging {
        background: green;
    }
</style>
<ul class="pat-sortable">
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
</ul>

Table

The patttern needs to be defined on the direct parent element of the elements to be sorted. Heads up: A would be added to the table by browser automatically. The pattern needs to be defined on the then.

One One One Two
Two One Two Two
Three One Three Two
<table class="table table-stripped">
    <tbody class="pat-sortable" data-pat-sortable="selector:tr;">
        <tr>
            <td>One One</td>
            <td>One Two</td>
        </tr>
        <tr>
            <td>Two One</td>
            <td>Two Two</td>
        </tr>
        <tr>
            <td>Three One</td>
            <td>Three Two</td>
        </tr>
    </tbody>
</table>