EasyUI Forum
May 04, 2024, 09:19:29 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Hide property for tree nodes  (Read 13999 times)
fl0
Newbie
*
Posts: 10


View Profile
« on: May 07, 2013, 01:30:59 AM »

Hello again,

still working with your nice tree. As you know from the bugs forum i kinda use everything it has to offer Wink
Now i'd have a little featurewish for the tree. Could you implement a "hidden" property, which determines whether a node is displayed in the tree or not. I've an inputfield to search for values in the tree with the following functions:

    $('#search').keyup(function() {
        $('#tree').tree('collapseAll');
        //$('#tree').tree('hideAll');
        var root = $('#tree').tree('getRoot');
        find($('#tree'), root, $('#search').val());
    });

    function find(tree, node, needle) {
        var children = tree.tree('getChildren', node.target);
        var found = false;
        $.each(children, function(key, value) {
            found = find(tree, value, needle) || found;
        });
        if (found || node.text.indexOf(needle) !== -1) {
            tree.tree("expand", node.target);
            //tree.tree("unhide", node.target);
            return true;
        }
        return false;
    }

By now it collapses the tree and expands all nodes where a specific string is found. My problem is that the tree i work an is really really large and almost every node has a hell of a lot subnotes. So whenever i search for a string, all nodes, that have a parent on the path are displayed. I would basicly need the following functions:

tree("hideAll")
tree("unhide", node)

for completeness i recommend also
tree("unhideAll")
tree("hide", node)

Is it possible that you include such a feature in the future? Also feel free to use my code for a tree("findString", node, needle) function Wink

Thanks in advance
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 07, 2013, 02:03:18 AM »

The 'hide' and 'unhide' methods can be extended as:
Code:
<script>
$.extend($.fn.tree.methods,{
hide: function(jq,target){
return jq.each(function(){
$(target).parent().hide();
});
},
unhide: function(jq,target){
return jq.each(function(){
$(target).parent().show();
});
}
});
</script>

The code below shows how to hide the selected node.
Code:
var node = $('#tt').tree('getSelected');
if (node){
  $('#tt').tree('hide',node.target);
}
Logged
fl0
Newbie
*
Posts: 10


View Profile
« Reply #2 on: May 08, 2013, 12:43:29 AM »

Works perfect. Thx.

Will this be implemented in the next release?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!