Jump to content

[Solved] UniTreeMenu Filter


Gabriel

Recommended Posts

Hi.

 

I have a problem filtering the UniTreeMenu. I've adapted this method from Extjs

 

 filterStore: function(value) {
                var me = this,
                    store = me.store,
                    searchString = value.toLowerCase(),
                    filterFn = function(node) {
                        var children = node.childNodes,
                            len = children && children.length,
                            visible = v.test(node.get('text')),
                            i;

                        // If the current node does NOT match the search condition
                        // specified by the user...
                        if (!visible) {

                            // Check to see if any of the child nodes of this node
                            // match the search condition.  If they do then we will
                            // mark the current node as visible as well.
                            for (i = 0; i < len; i++) {
                                if (children[i].isLeaf()) {
                                    visible = children[i].get('visible');
                                } else {
                                    visible = filterFn(children[i]);
                                }
                                if (visible) {
                                    break;
                                }
                            }

                        } else { // Current node matches the search condition...

                            // Force all of its child nodes to be visible as well so
                            // that the user is able to select an example to display.
                            for (i = 0; i < len; i++) {
                                children[i].set('visible', true);
                            }

                        }

                        return visible;
                    },
                    v;

                if (searchString.length < 1) {
                    store.clearFilter();
                } else {
                    v = new RegExp(searchString, 'i');
                    store.getFilters().replaceAll({
                        filterFn: filterFn
                    });
                }

look like this

 

blob.png.96ccba196abd013e8baba6b341d43629.png

The code was working great, until a uniGUI update, i believe it was 1498 wich introduce Ext js 6.7 (not sure). Since that update the code isn't working anymore, it does not filter the tree and furthermore, is not expanding all the tree nodes. Anyone knows anything about this? 

I cant use the filter as is it show on the demo files, because my tree is dynamically created. (related post: 

 

Regards

Link to comment
Share on other sites

16 minutes ago, Gabriel said:

I cant use the filter as is it show on the demo files, because my tree is dynamically created

Hi,

Can you make a simple testcase? Then please indicate the sequence of actions, how to work with a testcase.

Link to comment
Share on other sites

I've changed a little bit the test case...

 

What I was trying to accomplish is to hide all elements from the menu, it should be pretty straight forward, but, I think I found that the menu is not refreshing after setting the property. I add this function to the KeyUp event

 

function keyup(sender,e,eOpts){
	var me = MainForm.UniTreeMenu1;
	var almc = me.store;
	var vItemGlobal = '';
	console.log('----Start----');
	for(var i=0; i< almc.data.items.length;i++){
		var vItem = almc.data.items[i].get('text');
		vItemGlobal = vItemGlobal + '-' + vItem;
	}
	
	console.log('Hide elements');
	for(var i=0; i< almc.data.items.length;i++){
		almc.data.items[i].set('visible',false);
	}
	console.log('After hide');
	for(var i=0; i< almc.data.items.length;i++){
		console.log(almc.data.items[i].get('text'));
		if(almc.data.items[i].get('visible')){
			console.log(' - - - Is visible');
		}
	}
	
	console.log('List: ' +vItemGlobal);
	console.log('----End----');
	
}

And the result was this (console log)

 

js.js:5 ----Start----
js.js:11 Hide elements
js.js:15 After hide
js.js:17 Item two
js.js:19  - - - Is visible
js.js:17 Item four
js.js:19  - - - Is visible
js.js:17 Empleados
js.js:19  - - - Is visible
js.js:17 Metodos y Reportes
js.js:19  - - - Is visible
js.js:17 Informes de Gestión
js.js:19  - - - Is visible
js.js:23 List: -Item one-Item two-Item tree-Item four-Empresa-Empleados-Plan Vacacional-Metodos y Reportes-Autogestión-Informes de Gestión
js.js:24 ----End----
 //second run
undefined
js.js:5 ----Start----
js.js:11 Hide elements
js.js:15 After hide
js.js:17 Item four
js.js:19  - - - Is visible
js.js:17 Metodos y Reportes
js.js:19  - - - Is visible
js.js:23 List: -Item two-Item four-Empleados-Metodos y Reportes-Informes de Gestión
js.js:24 ----End----
//third
undefined
js.js:5 ----Start----
js.js:11 Hide elements
js.js:15 After hide
js.js:17 Metodos y Reportes
js.js:19  - - - Is visible
js.js:23 List: -Item four-Metodos y Reportes
js.js:24 ----End----
//fourth
undefined
js.js:5 ----Start----
js.js:11 Hide elements
js.js:15 After hide
js.js:23 List: -Metodos y Reportes
js.js:24 ----End----

The menu is still the same

 

blob.png.fc29323d24d5306e1d1ec84409eabaa2.png

 

I attach the updated project. The javascript code is in the Release/files folder 

 

Regards

UniTestMenu.rar

Link to comment
Share on other sites

  • 1 month later...
  • 8 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...