EasyUI Forum
November 05, 2025, 08:42:13 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: Tree - dynamically change icon with Formatter  (Read 11904 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: April 14, 2015, 05:29:44 AM »

Hi;

Can I use the formatter to change the node icon, this appears to cause recursion:

Code:
formatter:function(node){
switch(node.id){
case "x":
var cls = 'aicon-user';
break;
case "y":
var cls = 'aicon-group';
break;
}

$(this).tree('update',{target:node.target,iconCls:cls})
}
Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: April 14, 2015, 08:07:00 AM »

The 'formatter' function only render the node's text. Please try to use the 'loadFilter' function to change the node's icon.
Code:
$('#tt').tree({
loadFilter: function(data, parent){
function forNodes(data, callback){
var nodes = [];
for(var i=0; i<data.length; i++){
nodes.push(data[i]);
}
while(nodes.length){
var node = nodes.shift();
if (callback(node) == false){return;}
if (node.children){
for(var i=node.children.length-1; i>=0; i--){
nodes.unshift(node.children[i]);
}
}
}
}
forNodes(data, function(node){
if (node.id == 'x'){
node.iconCls = 'icon-user';
}
});
return data;
}
})
Logged
LastByte
Newbie
*
Posts: 2


View Profile
« Reply #2 on: October 13, 2015, 10:36:21 AM »

Is there any way to correctly assign the node icon class/image in a tree.
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!