Moey Icons
No results. Try “dialog”, “dark” or “grid”.
Moey extras

Sortable

Drag things into the order you want — tasks, menu items, table rows, dashboard cards. One attribute on the list. It works with a mouse, a finger (press and hold, or grab a handle) and the keyboard, and tells your app the new order so you can save it.

  • Write the product brief
  • Review the new checkout
  • Order packaging
  • Plan the holiday sale
  • Reply to wholesale leads

Drag a row by its handle — or Tab to a handle, Space, arrows, Space.

<ul class="list-group" data-moey-sortable>
  <li class="list-group-item" data-id="t1"><span class="sort-handle"></span>Write the product brief</li>
  <li class="list-group-item" data-id="t2"><span class="sort-handle"></span>Review the new checkout</li>
  …
</ul>

Add it, step by step

  1. Add data-moey-sortable to the list — a ul, an ol, a .list-group, a grid of cards, or a table's tbody. Its children become draggable.
  2. Give each item a data-id so you know which is which when you save.
  3. Decide how it is grabbed. Put an empty <span class="sort-handle"></span> (six dots) in each item and only the handle drags — best when the item has links or buttons, and on touch it starts at once. Without handles the whole item drags; on touch, press and hold first (a plain swipe still scrolls).
  4. Save the order in moey:sort — read Moey.sortable(list).value() (the ids, in order) and send it to your server. Say no with e.preventDefault() and the item goes back.
list.addEventListener('moey:sort', (e) => {
  const { id, fromIndex, index } = e.detail;          // 't3', 2, 0
  saveOrder(Moey.sortable(list).value());             // ['t3', 't1', 't2', 't4', 't5']
});

A grid of cards

Rows and grids work the same — here without handles, so the whole card drags (press and hold on touch). Arrange your dashboard:

Revenue$48,210
Orders1,284
Customers932
Refunds23
Visits9,980
Reviews4.8 ★
<div class="grid grid-cols-2 md:grid-cols-3 gap-3" data-moey-sortable>
  <div class="card" data-id="revenue">…</div>
  <div class="card" data-id="orders">…</div>
  …
</div>

Table rows

Put data-moey-sortable on the tbody and a handle in the first cell.

MoveProductPriceStock
Linen shirt$49.00124
Canvas tote$29.00312
Wool beanie$24.0088
Leather wallet$59.0041
<table class="table">
  <thead><tr><th><span class="visually-hidden">Move</span></th><th>Product</th>…</tr></thead>
  <tbody data-moey-sortable>
    <tr data-id="p1"><td><span class="sort-handle"></span></td><td>Linen shirt</td>…</tr>
    …
  </tbody>
</table>

Between lists

Give several lists the same name — data-moey-sortable="tasks" — and items move between them. e.detail.from and e.detail.to are the lists. (For a full board with columns, counts and limits, see Kanban.)

Today
  • Pack 12 orders
  • Call the courier
  • Photograph new bags
Later
  • Update the FAQ
  • Try a new supplier
<ul class="list-group" data-moey-sortable="tasks" data-id="today">…</ul>
<ul class="list-group" data-moey-sortable="tasks" data-id="later">…</ul>

<script>
  document.addEventListener('moey:sort', (e) => {
    moveTask(e.detail.id, e.detail.to.dataset.id, e.detail.index);   // 'b', 'later', 0
  });
</script>

On a phone

Press and hold — or use the handles

Keyboard

Tab to an item (or its handle), Space picks it up, ↑ ↓ move it (← → in a row of cards), Home / End to the top or bottom, Space drops and Esc puts it back. Each step is read out ("position 2 of 5").

Reference

Class / attributeWhat it does
data-moey-sortableIts children can be dragged into a new order
data-moey-sortable="name"Lists with the same name share items
data-id on itemsWhat value() and the event report
.sort-handleThe grip (empty: six dots); with handles only they drag, and touch starts at once
.sort-labelThe text read out when the item moves (else the item's title or text)
data-moey-no-sort · data-moey-no-dragOn an item: it stays put · inside an item: this part doesn't start a drag
Event moey:sortOn the item, cancelable: detail: { item, id, from, to, fromIndex, index }
Moey.sortable(list){ value() → ids, move(item | id, index) }