TreeGrid
Adds expandable branches to the DataGrid.
When to use
- Show detail rows within a hierarchy such as cost centers and budget lines.
Examples
Bind nested data
Loading the example
<k:TreeGrid id="tree" label="Cost centers" height="13rem" rows="{path:'/nodes', parameters:{arrayNames:['children']}}" openLevels="0">
<k:columns>
<k:Column label="Cost center" path="name" grow="1"/>
<k:Column label="Budget" path="budget" type="number"/>
</k:columns>
</k:TreeGrid>Control expansion depth
Loading the example
<k:Stack gap="8">
<k:Button text="Expand cost centers" press=".onExpand"/>
<k:TreeGrid id="tree" label="Cost centers" height="13rem" rows="{path:'/nodes', parameters:{arrayNames:['children']}}" toggle=".onToggle" openLevels="0">
<k:columns>
<k:Column label="Cost center" path="name" grow="1"/>
<k:Column label="Budget" path="budget" type="number"/>
</k:columns>
</k:TreeGrid>
</k:Stack>sap.ui.define(["sap/ui/core/mvc/Controller", "kor/ui/Toast"], (Controller, Toast) => Controller.extend("sample.BudgetTree", {
onExpand() {
this.byId("tree").expandToLevel(1);
Toast.show("Cost centers expanded");
},
onToggle(event) {
Toast.show(event.getParameter("context").getProperty("name"));
}
}));Keyboard
- ← →
- Collapse or expand the focused branch.
API
Also has everything from DataGrid
Properties
| Name | Type | Default | Description |
|---|---|---|---|
openLevels | int | 1 | Number of levels initially expanded |
Events
| Name | Type | Description |
|---|---|---|
toggle | context: objectopen: boolean | A branch opened or closed and may load children |
Methods
| Name | Description |
|---|---|
toggle(row: number, to?: boolean): void | Opens or closes a branch at a visible row index |
expandToLevel(level: number): void | Expands branches to the given level. Zero closes all branches |
getState(): object | Returns column state and the paths of open branches |
setState(state: Parameters<DataGrid["setState"]>[0] & { open?: string[] }): void | Restores column state and open branches |