This content originally appeared on DEV Community and was authored by Ray
Question title
How to progressively load sub-nodes in a list with the VTable component?
Problem description
Using the VTable table component, how to gradually load sub-nodes in the list, click the expand button of the parent node, and then dynamically load the information of the sub-node
Solution
VTable provides setRecordChildren
API to update the sub-node status of a node, which can be used to implement progressive loading function
- Data preparation
Normally, in the data of the tree structure list, the children
attribute is an array, which is the sub-node information of the node
{
name: 'a',
value: 10,
children: [
{
name: 'a-1',
value: 5,
children: [
// ......
]
},
// ......
]
}
How to dynamically load sub-node information, you can configure the children
property to true
. At this time, the node will be displayed as the parent node in the table, but clicking the expand button in the cell will trigger relevant events, but the table will not have any active changes.
- Monitoring events
After the expand button is clicked, the VTable. ListTable.EVENT_TYPE
event will be triggered. You need to listen to this event and use the setRecordChildren
API to update the sub-node information
const { TREE_HIERARCHY_STATE_CHANGE } = VTable.ListTable.EVENT_TYPE;
instance.on(TREE_HIERARCHY_STATE_CHANGE, args => {
if (args.hierarchyState === VTable.TYPES.HierarchyState.expand && !Array.isArray(args.originData.children)) {
setTimeout(() => {
const children = [
{
name: 'a-1',
value: 5,
},
{
name: 'a-2',
value: 5
}
];
instance.setRecordChildren(children, args.col, args.row);
}, 200);
}
});
Code example
demo:https://visactor.io/vtable/demo/table-type/list-table-tree-lazy-load
Related Documents
Related api: https://visactor.io/vtable/option/ListTable-columns-text#tree
Tutorial: https://visactor.io/vtable/guide/table_type/List_table/tree_list
github:https://github.com/VisActor/VTable
This content originally appeared on DEV Community and was authored by Ray
Ray | Sciencx (2024-07-04T03:32:57+00:00) How the VTable component progressively loads sub-nodes in a list?. Retrieved from https://www.scien.cx/2024/07/04/how-the-vtable-component-progressively-loads-sub-nodes-in-a-list/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.