Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Trees and Reordering

A list keeps its rows in an order of their own, shows them as a tree on a parent column, or both.

Reorder rows

list:
  reorder: true
list:
  reorder: { column: position }
ListConfig::new("pages", "Pages", columns).reorder("position")
KeyDefaultDoes
reorderofftrue keeps the order in sort_order; { column: position } names the column. An integer column, not null, default 0.
reorder.columnsort_orderThe column holding each row’s position.

The list opens in that order with a grip to drag and Move up / Move down on every row; a sorted, searched or filtered view shows neither. A has-many section’s list takes the same key; see Related Records.

Show rows as a tree

list:
  tree: true
list:
  tree: { parent_key: folder_id, source: acme.folders }
use laterite_admin::list::TreeConfig;

ListConfig::new("folders", "Folders", columns)
    .tree(TreeConfig::new("folder_id").move_to("acme.folders"))
KeyDefaultDoes
treeofftrue reads the parent from parent_id; { parent_key, source } names the column and a picker source.
tree.parent_keyparent_idThe column holding a row’s parent id, null at the top level.
tree.sourcenoneA registered picker source over this entity. With it, every row offers “Move to”, which picks the new parent from the source or leaves it empty for the top level. A record never moves under itself.

The list opens on the rows with no parent; a row with children expands in place, or opens them as a page with scripting off. With reorder too, a move stays among one parent’s children. A has-many section ignores tree.

Reach the routes

PathMethodDoes
/products/reorderPOSTMoves id with move=up or move=down, or before=<id> or after=<id>, and shows page again; parent names the branch under a tree.
/products/7/moveGET, POSTThe “Move to” form for record 7, and the move itself.

Both answer an htmx request with the list region and a plain one with the page.