هذه الصفحة غير مترجمة بعد، وهي معروضة بالإنجليزية.

The data table shows nested rows when you pass getSubRows, a function that returns a row’s children. Rows with children get an expand toggle in their first cell, and each level is indented. Pass expanded with onExpandedChange to control which rows are open.

Engineering
Yuki Tanaka42
Product
Omar Haddad15
Customer care
Hana Kim12

Every row is collapsed.

Open Engineering, then Platform, to see two levels of sub-rows. The text under the table lists the expanded rows by id.

Sub-rows

getSubRows receives each row and returns its children, or undefined for a leaf. The children use the same columns as their parent. Give every row, at every level, an id with getRowId, so the expanded state, the selection and a row reorder follow the row and not its position.

For children that load later, getRowCanExpand decides which rows show a toggle before their children arrive; fetch the children when the row expands and put them in data.

Expanded state

  • expanded and onExpandedChange control it, as the demo does. The state is { [rowId]: true } for the open rows, or true for every row.
  • defaultExpanded sets a starting state the table keeps itself, such as { eng: true } or true to open everything.
  • paginateExpandedRows counts sub-rows towards the page size. By default only top-level rows count, so a page keeps its parents’ children with it.

The parts

The toggle is the ExpandToggle slot: a <button> with aria-expanded, named by the expandRow or collapseRow label. It receives expanded, depth and onToggle, and a click on it does not run onRowClick. A row with no children gets a spacer in its place, so the names line up. The built-in toggle also sets an empty data-expanded on itself while open, which its stylesheet uses to turn the chevron; a toggle of your own gets expanded and sets whatever it needs.

Each Row carries data-depth (0 for top-level rows) and, when it can expand, data-expanded ("true" or "false"), so a stylesheet can mark the levels.