Nested sortables
Each item can hold its own sortable list. All levels share the same group, so items can be dragged between branches and depths - into the empty list under any item, too. An item is never dropped inside itself.
Item 1.1
Item 2.1
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 2.2
Item 3.1
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 3.2
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 2.3
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 1.2
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 1.3
Item 2.4
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 2.5
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Item 1.4
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Tree: Item 1.1 [Item 2.1, Item 2.2 [Item 3.1, Item 3.2], Item 2.3], Item 1.2, Item 1.3 [Item 2.4, Item 2.5], Item 1.4
Try it
- Drag Item 3.1 up into the top level, between Item 1.1 and Item 1.2.
- Drag Item 1.2 into the empty dashed area under Item 2.1: it becomes a child of 2.1, one level deeper.
- Drag Item 1.1 over its own children: none of them takes it - an item cannot be dropped inside itself - and its whole branch moves with it wherever it does land.
- From the keyboard, pick an item up with Space: the arrows carry it into a nested list and out again, in the direction they point.
How it works
NestedListis a component of the demo's own: aBortablewhoseItemTemplaterenders anotherNestedListfor the item's children. Every level hasGroup="nested", so any list of the tree takes an item from any other.- The lists inside the dragged item's own subtree, and the lists inside the drop preview, refuse it - so an item is never dropped inside itself.
- Each list handles its own items only: a drag that starts in an inner list is not also a drag of the outer item around it.
-
A nested list takes the pointer only for a drag it could receive. One of another group, of another item type,
or with
Put="false"leaves the drag to the list around it - which is how the columns of a board still sort while the pointer crosses the card lists inside them. - Every item renders a list of its own, empty or not, with padding and a minimum height in this page's stylesheet, so an empty branch still has an area to drop into.
-
Each list is bound one way, with
Items, to the item'sChildren, which the list changes in place.ItemsChangedonly tells the page to render the tree line again.
Parameters on this page
| Parameter | Here | What it does |
|---|---|---|
Items | item.Children | The children of the item the list belongs to, changed in place. |
ItemsChanged | OnItemsChanged | Raised once per drag for each list that changed - here, to show the new tree. |
Group | nested | Every level shares it, so items move between branches and depths. |
SwapThreshold | 0.65 | The value the SortableJS nested demo uses: the outer part of each item is a dead zone. See swap thresholds. |
Id | nested-item-1-1, ... | Follows the item that owns the list, wherever the item moves. |