I updated the code in the first post to implement the config "hideEmptyFolders". It will hide any folders with no visible children.

The speed seems a little slower but it's hardly noticeable.

20 Dec 2012, 1:32 PM

hhangus

I made one more update just now because the hideEmptyFolders feature did not un-hide empty folders after clearing filters, oops lol.

21 Dec 2012, 6:59 AM

Bcg24

Any suggestion on how to actually filter the folders, though?

21 Dec 2012, 10:29 AM

Bcg24

The current code that takes care of hiding empty folder looks at hasVisibleChild to see if it should hide the folder. the problem is, hasVisibleChild is always marked as true in the case of any folders as children, even if those folders leafs will ultimately be hidden...

2 Jan 2013, 11:23 AM

hhangus

>>the problem is, hasVisibleChild is always marked as true in the case of any folders as children, even if those folders leafs will ultimately be hidden...

This should not be the case. Any child folders that themselves have no visible children should be hidden, thus their parent, if it is similarly empty, should not be hidden. You may be having an issue with the maxExpandDepth though, because this will prevent filtering beyond the depth specified. Try setting the depth to 100 and see if it solves your problem.

Alternatively, it is often easier to modify the server code to include a parameter on nodes that can then be used to filter them appropriately on the client side. For example, you might include the node parameter "doNotFilter" true/false and check for that in your filterFn.

4 Feb 2013, 2:05 PM

zombeerose

@hhangus

Thank you for your code. Unfortunately, I was not able to get your solution to work. I tried implementing a similar approach to yours based on toggling node visibility but I was not pleased with the choppy effect when expanding/collapsing branches. Additionally, considering that Ext has stubbed out filter methods in the tree store, I felt that this approach would be more in line with their implementation. Using this stackoverflow post as a starting post, I wrote the following code. I have tested it against a pre-loaded tree (all children nodes are loaded immediately) and an async remote-loaded tree. I do not support a maxDepth like you did because most of my trees are several levels and filtering should apply to all nodes.

/**
* @property {Ext.util.MixedCollection} snapshot
* A pristine (unfiltered) collection of the records in this store. This is used to reinstate
* records when a filter is removed or changed
*/
me.snapshot = me.snapshot || me.getRootNode().copy(null, true);

//identify all the other nodes that should be removed (either they are not visible or are not a parent of a visible node)
resultNodes = [];
root.cascadeBy(function(n){
if (!Ext.Array.contains(visibleNodes,n)){
resultNodes.push(n);
}
});
//we can't remove them during the cascade - pulling rug out ...
length = resultNodes.length;
for (i = 0; i < length; i++){
resultNodes[i].remove();
}
//filtering should NOT add rows to the queue of records to remove ... we reverse this from happening
me.removed = removedRecords;

Can you explain why you "had to change" it to an extend vs override? Both options should work ... override affects everything while extends applies to a custom class used explicitly. Thx

6 May 2013, 8:02 AM

pierrocknroll

Well I have a strange error "object is not a function" from nowhere :) It's maybe because I have a big application with several custom components.

By the way, I have an other problem : the records ids are changed after filtering so getNodeById doesn't work.

6 May 2013, 8:08 AM

hhangus

Hi zomberose

I originally implemented my filters on the store as you have done (in fact it's almost identical). The reason I moved away from doing it this way was because it turned out to be very slow on large datasets. The root.copy function is very time consuming and must be done each time the filtering changes.

I switched to filtering the View because it is an order of magnitude faster for me.

In any case, if you wish to discuss your extension and provide support I ask that you please create your own forum post for it rather than mucking up this one.