Tree ^0.7.0
Enable tree function in two steps
- Set
StkTableColumn['type']
totree-node
to specify the position of the tree expansion button
const columns: StkTableColumn<any>[] = [
{ type: 'tree-node', title: 'Area', dataIndex: 'area' },
]
- Add
children
field to the data source. After clicking, the content in thechildren
field of the data will be displayed as child nodes.
export const getDataSource = () => [
{
area: 'Asia',
gdp: 10000,
population: 50000000,
gdpPerCapita: 20000,
children: [
{ area: 'China', gdp: 5000, population: 1400000000, gdpPerCapita: 35000, },
{ area: 'Japan', gdp: 4000, population: 126000000, gdpPerCapita: 33000, }
],
},
];
Simple Tree
Default Expanded Nodes
Expand All
treeConfig.defaultExpandAll = true
Expand Specific Level
treeConfig.defaultExpandLevel = 1
Expand Specific Nodes
treeConfig.defaultExpandedKeys = ['Asia', 'China', 'Zhejiang']
Virtual List
Note
The component will inject the __T_EXPANDED__
field into each row of the dataSource to control whether it is expanded. Do not modify this field when updating the data of a row. Therefore, Object.assign
is used in the example to update data.
Performance Note
Even with virtual lists, every change in props.dataSource
will cause the component to internally traverse dataSource
to flatten the data. Therefore, for frequently changing data, it will occupy more computing resources of the computer. If you have certain performance requirements, you can refer to Example - Large Data to implement the tree expansion logic yourself.