Extjs treePanel filter query function [to], extjstreepanel
In Extjs4.2, The filterBy function is not implemented in treeStore, and treestore does not inherit from Ext. data. Store. The treePanel filter query function can be implemented in the following two ways:
I. FilterBy Function
Implementation ideas:
1) For the treestore structure type, extjs provides a special iteration function, cascadeBy function, which is used to iterate on Tree nodes.
2) iterative tree structure: In the callback function, determine whether the queried content exists. If yes, put the node id in the array.
3) iterate the tree structure again to hide nodes not in the data.
4) All nodes are visible during each query.
Note: In extjs, you can use Ext. dom. Element to display the dom of interface elements.
First define a class 'myextend. lib. treefilter'
/*** Created by bcm on 14-6-30. */Ext. define ('myextend. lib. treefilter', {filterByText: function (text) {this. filterBy (text, 'text') ;},/*** filter all nodes based on the string and hide nodes that do not meet the conditions. * @ param query string. * @ param: the column to be queried. */filterBy: function (text, by) {// debugger; this. clearFilter (); var view = this. getView (), me = this, nodesAndParents = []; // locate the matched node and expand it. // Add matched nodes and their parent nodes to the nodesAndParents array. this. getRootNode (). CascadeBy (function (tree, view) {var currNode = this; if (currNode & currNode. data [by] & currNode. data [by]. toString (). toLowerCase (). indexOf (text. toLowerCase ()>-1) {me. expandPath (currNode. getPath (); while (currNode. parentNode) {nodesAndParents. push (currNode. id); currNode = currNode. parentNode ;}}, null, [me, view]); // hide this. getRootNode (). cascadeBy (function (tr Ee, view) {var uiNode = view. getNodeByRecord (this); if (uiNode &&! Ext. array. contains (nodesAndParents, this. id) {Ext. get (uiNode ). setDisplayed ('None') ;}, null, [me, view]) ;}, clearFilter: function () {var view = this. getView (); this. getRootNode (). cascadeBy (function (tree, view) {var uiNode = view. getNodeByRecord (this); if (uiNode) {Ext. get (uiNode ). setDisplayed ('table-row') ;}, null, [this, view]) ;}});
Next, define your own treepanel and mix it into the class.
Ext.define('MyTreePanel',{ extend:'Ext.tree.Panel', mixins:['MyExtend.lib.TreeFilter'] });
Implementation result diagram:
Ii. searchTables Function
Implementation ideas:
1) cyclically iterate the tree structure and use regular expressions for matching. Expand and select matched nodes.
2) then, match the child node of the iteration node to expand and select the node.
// Treepanel fuzzy query. Expand the tree structure and select the matching function searchTables (tree, value) {tree. forEach (function (e) {var content = e. raw. text; var re = new RegExp (Ext. escapeRe (value), 'I'); if (re. test (content) | re. test (content. toUpperCase () {e. parentNode. expand (); var tabllepanel = Ext. componentQuery. query ('auditruleview treepanel [name = dataTables] ') [0]; var selModel = tabllepanel. getSelectionModel (); selModel. select (e, tru E); if (! E. isLeaf () {e. expand () ;}} searchTables (e. childNodes, value );});}
Implementation: