EasyUI Forum
June 16, 2024, 01:31:19 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to remove all the nodes of a tree  (Read 7813 times)
forum6691
Newbie
*
Posts: 39


View Profile
« on: May 09, 2014, 08:45:42 AM »

Hello
How to remove all the nodes of tree (like a clear method for example)?

There is the remove function but it's for ONE node whose you know already the 'id', but if you don't know what nodes are inside the tree, how to do ?

Thanks for your help.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 09, 2014, 09:20:36 AM »

Removing a tree node doest not require the 'id' value. Here is the extended method to remove all the tree nodes.
Code:
$.extend($.fn.tree.methods, {
removeAll:function(jq){
return jq.each(function(){
var roots = $(this).tree('getRoots');
for(var i=roots.length-1; i>=0; i--){
$(this).tree('remove', roots[i].target);
}
})
}
})

Calling 'removeAll' method will remove all the tree nodes.
Code:
$('#tt').tree('removeAll');
« Last Edit: September 12, 2014, 05:12:06 AM by stworthy » Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #2 on: May 09, 2014, 10:12:31 AM »

Thank you very much sworthy
Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #3 on: September 12, 2014, 04:17:51 AM »

I try to use the code you proposed sworthy, but it removes only one par one the nodes of the tree.

See here the demo I wrote with this problem : http://jsfiddle.net/30ddrjkj/11/

Thanks for your help
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: September 12, 2014, 05:12:47 AM »

Please try the updated example http://jsfiddle.net/30ddrjkj/13/
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!