Use TreeDataGrid when records need columns, sorting, cell editing, or expandable child rows. For a simple selectable list, start with 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
Section titled “Run the data-grid demo”cargo run -p treedatagrid-demoOpen the Countries page to try sorting and filtering, then People to try declarative columns and hierarchy. The demo source includes the data models, theme setup, and view registration.
Define a view with columns
Section titled “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 for typed XAML.
<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 adds compiled bindings, a child expander, a template column, and check boxes.
Create the grid from declarative Rust
Section titled “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:
let source = use_hook(languages); // a function returning a TreeDataGridSourceRefrsx! { TreeDataGrid { source: source } }See the ViewGallery source for the source and its columns (cargo run -p view-gallery).
Choose a source model
Section titled “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 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
Section titled “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
Section titled “Keep the viewport bounded”Place the grid in a * row of a constrained 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
Section titled “Public APIs and controls”- TreeDataGrid — registered properties and markup.
FlatTreeDataGridSourceandHierarchicalTreeDataGridSource— application data sources.AccessorandTextColumn— item access and columns.- Collection notifications and layout — the underlying patterns.