I originally posted this on the Sencha forums here , but have not received any answers (other than my own answer, which I will post shortly), so I am going to post it here and see if I get any more help.
I was trying to figure out how to filter a TreeStore in 4.0.7. I tried the following:
Model
Ext.define('model', { extend: 'Ext.data.Model', fields: [ {name: 'text', type: 'string'}, {name: 'leaf', type: 'bool'}, {name: 'expanded', type: 'bool'}, {name: 'id', type: 'string'} ], hasMany: {model: 'model', name: 'children'} });
Score
Ext.define('myStore', { extend: 'Ext.data.TreeStore', model: 'model', storeId: 'treestore', root: { text: 'root', children: [{ text: 'leaf1', id: 'leaf1', children: [{ text: 'child1', id: 'child1', leaf: true },{ text: 'child2', id: 'child2', leaf: true }] },{ text: 'leaf2', id: 'leaf2', leaf: true }] }, proxy: { type: 'memory', reader: { type: 'json' } } });
Tree
var myTree = Ext.create('Ext.tree.Panel', { id: 'myTree', selType: 'cellmodel', selModel: Ext.create('Ext.selection.CellModel', {mode: 'MULTI'}), rootVisible: false, store: Ext.create('myStore'), width: 300 });
Filter
var filter = Ext.create('Ext.util.Filter', { filterFn: function(item) { return item.data.text == 'leaf1'; } });
So, I think that my problem ... I do not know how to use this filter because TreeStore does not actually inherit any filter functions, such as a regular store. I tried:
myTree.store.filters.add(filter); myTree.store.filters.filter(filter);
Usually, if I have a grid and I create a filter as above, I can just do myTree.store.filter(filter)
, and it will capture every element / filter of the row on what I return ... but I guess because TreeStore doesn't inherit a filter function that is not passed.
If someone can give some clarity about what I'm doing wrong, or clarify how to set up the filter function / my thinking process, please continue. I would appreciate any help.