# Display tabular and hierarchical data

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/ecosystem/treedatagrid/

Use TreeDataGrid when records need columns, sorting, cell editing, or expandable child rows. For a simple selectable list, start with [ListBox](/docs/0.5.0/controls/reference/listbox/) instead.

Add `ferroui-controls-treedatagrid` and the data-model crate `ferroui-treedatagrid-core` at the same version as your framework. Register the control types and load the matching theme resources; the complete demo shows that setup.

## Run the data-grid demo

```sh
cargo run -p treedatagrid-demo
```

Open the Countries page to try sorting and filtering, then People to try declarative columns and hierarchy. [The demo source](https://github.com/wieslawsoltes/FerroUI/tree/d503df2befa756e681fcdc6250e9552dc7388bea/samples/TreeDataGridDemo) includes the data models, theme setup, and view registration.

## Define a view with columns

In XAML, this fragment expects a registered `People` collection on the view model and registered `Name` and `Title` properties on each item. It uses runtime bindings to keep the example independent of an application's namespace:

This fragment uses explicit reflection bindings because it omits your application’s registered source types. See [compiled binding setup](/docs/0.5.0/xaml/compilation/#migrate-to-compiled-bindings-by-default) for typed XAML.

```xml
<TreeDataGrid xmlns="https://github.com/ferroui"
              ItemsSource="{ReflectionBinding People}" SelectionMode="Row,Multiple">
  <TreeDataGridTextColumn Header="Name" Width="2*" Binding="{ReflectionBinding Name}" />
  <TreeDataGridTextColumn Header="Title" Width="2*" Binding="{ReflectionBinding Title}" />
</TreeDataGrid>
```

`ItemsSource` supplies records; column bindings read each record. The [People XAML example](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/samples/TreeDataGridDemo/Views/PeopleXamlPage.xaml) adds compiled bindings, a child expander, a template column, and check boxes.

## Create the grid from declarative Rust

With the `treedatagrid` feature of `ferroui-view`, the grid and its cells and rows have builders like every other control. A component keeps the source in a hook and gives it to the grid's `source` property; the ViewGallery sample builds a `FlatTreeDataGridSource` with three text columns this way:

```rust
let source = use_hook(languages); // a function returning a TreeDataGridSourceRef
rsx! { TreeDataGrid { source: source } }
```

See the [ViewGallery source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/samples/ViewGallery/lib.rs) for the source and its columns (`cargo run -p view-gallery`).

## Choose a source model

| Need | Starting point |
| --- | --- |
| Flat records with programmatic columns | `FlatTreeDataGridSource` |
| Records with expandable children | `HierarchicalTreeDataGridSource` |
| Columns declared alongside the view | `ItemsSource` and XAML column declarations |
| Framework-neutral column models | Core source assigned through the control's `Model` path |

For programmatic columns, accessors describe how to read and optionally write item properties. Use the public [Countries view model](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/samples/TreeDataGridDemo/ViewModels/countries_page_view_model.rs) as an end-to-end example of a notifying list, text columns, a template column, filtering, and row selection.

## Make edits and selection survive updates

Keep record identity stable. Notify item property changes when a cell value changes, and notify collection changes when adding or removing records. A plain vector mutation does not tell the grid what changed.

Choose whether the task selects rows or cells. When deleting or filtering a selected record, update the application's selection deliberately. For hierarchy, decide where expansion state lives so a refresh does not unexpectedly close every node.

## Keep the viewport bounded

Place the grid in a `*` row of a constrained [Grid](/docs/0.5.0/controls/reference/grid/). Avoid wrapping it in another scrolling container. Test with enough rows and columns to require scrolling, and verify keyboard editing, empty data, and theme changes.

## Public APIs and controls

- [TreeDataGrid](/docs/0.5.0/controls/reference/treedatagrid/) — registered properties and markup.
- [`FlatTreeDataGridSource`](/docs/0.5.0/api/ferroui-treedatagrid-core/struct-flattreedatagridsource/) and [`HierarchicalTreeDataGridSource`](/docs/0.5.0/api/ferroui-treedatagrid-core/struct-hierarchicaltreedatagridsource/) — application data sources.
- [`Accessor`](/docs/0.5.0/api/ferroui-treedatagrid-core/accessor/struct-accessor/) and [`TextColumn`](/docs/0.5.0/api/ferroui-controls-treedatagrid/models/struct-textcolumn/) — item access and columns.
- [Collection notifications](/docs/0.5.0/guides/collections/) and [layout](/docs/0.5.0/design/layout/) — the underlying patterns.
