Masu.Tree (Masu v0.1.0)

Copy Markdown View Source

Rows in a tree: children with the columns of their parent, indented, opened and closed.

<.data_grid id="accounts" rows={@accounts} tree={:parent_id}>

tree names the field of a row that holds its parent's id (or is a function of the row that gives it); a row whose parent is nil, or not among the rows, is a root. The grid shows the roots, and the children of each row the person opens, as one list: a tree of twenty thousand rows scrolls as a list of twenty thousand rows does, a block at a time.

Sorting sorts the children of each row among themselves. A filter or a search keeps the rows that match and their ancestors, so that a match is never shown without the rows above it; while one is applied, the rows it keeps are open, and the person may close them.

Both sources take tree (see Masu.Source.List and Masu.Source.Ecto). A source of your own implements Masu.Source.nodes/3.

Summary

Types

Where a row is in the tree: its level (0 for a root), whether it has children, whether it is expanded, its position among its siblings (from 1) and how many siblings there are (size).

Types

node_info()

@type node_info() :: %{
  level: non_neg_integer(),
  children: boolean(),
  expanded: boolean(),
  position: pos_integer(),
  size: pos_integer()
}

Where a row is in the tree: its level (0 for a root), whether it has children, whether it is expanded, its position among its siblings (from 1) and how many siblings there are (size).