Hybrid View
-
4 Sep 2007 6:13 AM #1
1.1 Treefilter
1.1 Treefilter
Hi All,
I have a tree of a +2000 nodes about 3 levels deep. It populates fine and quite quickly. I am testing treefilter before decding whether to round trip.
My code:
works except that it only returns top level nodes matching the criteria and their children! So it doesn't find nodes that are below the 1st level.PHP Code:var root = myTree.getRootNode();
var term = txtFind.getValue();
var re = new RegExp(term,'i');
myFilter.filter(re,'text',root);
Am I being stupid and missing something?
-
4 Sep 2007 6:16 AM #2
AsyncTreeNodes that are not viewed are not loaded. You have to expand a node once for its children to be loaded.
-
4 Sep 2007 6:19 AM #3
Ahhh, shot Animal!
Is there a way around this or is it best to do this server side?
-
4 Sep 2007 6:23 AM #4
It's a browser side thing.
You'll have to do a deep expand, with collapse as the callback (with animation turned off so that you don't see it happen).
This will ensure that what you think is there, is really there!
-
4 Sep 2007 6:25 AM #5
Looks like something to get my teeth into. Ta very much, Sir!
-
11 Oct 2007 9:35 PM #6
TreeFilter for 2.0
TreeFilter for 2.0
Searching about for a 2.0 treefilter, I found this thread. The 2.0 TreeFilter however, wasn't behaving in the manner in which I expected...so I baked this code up. It works pretty rapidly, on the principle of marking used paths from the leaves.
Use this on a text field with something like:Code:var hiddenPkgs = []; var markCount = []; // filter the kb tree for hits function filterTree(e){ var text = e.target.value; Ext.each(hiddenPkgs, function(n){ n.ui.show(); }); markCount = []; hiddenPkgs = []; if( text.trim().length > 0 ){ kb_tree.expandAll(); var re = new RegExp( Ext.escapeRe(text), 'i'); kb_tree.root.cascade( function( n ){ if( re.test(n.text) ) markToRoot( n, kb_tree.root ); }); // hide empty packages that weren't filtered kb_tree.root.cascade(function(n){ if( ( !markCount[n.id] || markCount[n.id] == 0 ) && n != kb_tree.root ){ n.ui.hide(); hiddenPkgs.push(n); } }); } } function markToRoot( n, root ){ if( markCount[n.id] ) return; markCount[n.id] = 1; if( n.parentNode != null ) markToRoot( n.parentNode, root ); }
Hope this saves someone some time! It will display all paths that lead to hits.Code:new Ext.form.TextField({ emptyText:'Find a subject', listeners:{ render: function(f){ f.el.on('keydown', filterTree, f, {buffer: 350}); } } })


Reply With Quote