Svelte Tree Grid

Hierarchical data is usually already in your rows: every record carries the id of its parent. Give SvGrid that field name and it builds the tree for you, indenting children under parents and putting an expander in the column you nominate. There is no separate tree component and no second data shape to maintain.

Everything the flat grid does keeps working. Sorting sorts within a level, filtering keeps the ancestors of a match visible, and children can be fetched on expand instead of loaded up front.

Install

npm i @svgrid/grid

Free and MIT-licensed in @svgrid/grid: no license key, no row cap, no watermark.

The code

<script lang="ts">
  import { SvGrid } from '@svgrid/grid'

  const people = [
    { id: 1, managerId: null, name: 'Ada Lovelace', title: 'CTO' },
    { id: 2, managerId: 1,    name: 'Grace Hopper', title: 'VP Engineering' },
    { id: 3, managerId: 2,    name: 'Alan Turing',  title: 'Staff Engineer' },
  ]
</script>

<SvGrid
  data={people}
  {columns}
  treeData={{ parentField: 'managerId', column: 'name' }}
/>

What you get

Live examples

Documentation

Related articles

Frequently asked questions

How do I show hierarchical data in a Svelte table?

Keep the flat array and add the treeData prop naming the field that holds each row's parent id, plus the column that should carry the expander. The grid nests and indents the rows for you.

Do I need nested arrays?

No. The common case is a flat list with a parent id, which is what treeData expects. Nested source data can be flattened once with a synthetic parent field, as the demo does.

Can children load on demand?

Yes. Fetch a node's children when it first expands, or use the server tree row model to page an entire hierarchy one level at a time.

Is the tree grid free?

Yes. Tree data, expansion, cascading selection and master-detail rows are MIT-licensed in @svgrid/grid.

Build something else

Get started · Browse the gallery · Pricing