Reputation: 343
Is there a way to hide a node (a parent or a child) in a treegrid? I set the visible property to false but it does not disappear: (here is the fiddle link: https://fiddle.sencha.com/#fiddle/jl1)
var tree = Ext.create('Ext.tree.Panel', {
renderTo: Ext.getBody(),
title: 'TreeGrid',
width: 300,
height: 250,
fields: ['name', 'description'],
columns: [{
xtype: 'treecolumn',
text: 'Name',
dataIndex: 'name',
width: 150,
sortable: true
}, {
text: 'Description',
dataIndex: 'description',
flex: 1,
sortable: true
}],
root: {
expanded: true,
children: [{
name: 'Group 1',
expanded: true,
children: [{
name: 'Child 1.1',
description: 'Description 1.1',
leaf: true
},{
name: 'Child 1.2',
description: 'Description 1.2',
leaf: true
}]
}, {
name: 'Group 2',
expanded: true,
children: [{
name: 'Child 2.1',
description: 'Description 2.1',
leaf: true
},{
name: 'Child 2.2',
description: 'Description 2.2',
leaf: true
}]
}]
}
});
var button = Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Remove group 1',
handler: function() {
var group1 = tree.getRootNode().childNodes[0];
group1.set('visible', false);
}
});
Note: I don't want to remove the node, I want to hide it, to show it again later (I want to do this because the remove/add behaviour on tree grid is very bugged :S) !
Thanks in advance :) !
Upvotes: 1
Views: 3865
Reputation: 692
You should work with tree store. Use filters to hide values from the tree.
I've fixed your fiddle. https://fiddle.sencha.com/#fiddle/jl8
I used filterBy
method to fix it. If the function returns true the Record is included to a tree, otherwise it is filtered out.
Here is some more documentation about that topic http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.TreeStore
Upvotes: 4