From 7bf9e916483dfd08a52429b920fc361d2d149649 Mon Sep 17 00:00:00 2001 From: cagataycivici Date: Tue, 6 Aug 2019 09:55:09 +0300 Subject: [PATCH] Programmatic Control for TreeTable and Dynamic Columns --- .../treetable/TreeTableRowLoader.vue | 2 +- src/views/treetable/TreeTableDemo.vue | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/components/treetable/TreeTableRowLoader.vue b/src/components/treetable/TreeTableRowLoader.vue index b5567176f..569e001f2 100644 --- a/src/components/treetable/TreeTableRowLoader.vue +++ b/src/components/treetable/TreeTableRowLoader.vue @@ -41,7 +41,7 @@ const TreeTableRowLoader = { const node = context.props.node; const expanded = context.props.expandedKeys && context.props.expandedKeys[node.key] === true; - if (expanded) { + if (expanded && node.children && node.children.length) { for (let childNode of node.children) { let childNodeProps = {...context.props}; childNodeProps.node = childNode; diff --git a/src/views/treetable/TreeTableDemo.vue b/src/views/treetable/TreeTableDemo.vue index 747dcfd41..021cfcd01 100644 --- a/src/views/treetable/TreeTableDemo.vue +++ b/src/views/treetable/TreeTableDemo.vue @@ -15,7 +15,24 @@ - + + +

Dynamic Columns

+ + + + +

Programmatic Control

+
+
+ + + + + @@ -31,12 +48,19 @@ export default { data() { return { nodes: null, + columns: null, expandedKeys: {} } }, nodeService: null, created() { this.nodeService = new NodeService(); + + this.columns = [ + {field: 'name', header: 'Vin', expander: true}, + {field: 'size', header: 'Size'}, + {field: 'type', header: 'Type'} + ]; }, mounted() { this.nodeService.getTreeTableNodes().then(data => this.nodes = data); @@ -53,6 +77,7 @@ export default { this.expandedKeys = {}; }, expandNode(node) { + this.expandedKeys[node.key] = true; if (node.children && node.children.length) { for (let child of node.children) {