Custom Icon Disappears when I add a New Node. Why?

112 views
Skip to first unread message

suresh2

unread,
Aug 3, 2012, 11:11:49 AM8/3/12
to dyna...@googlegroups.com
The custom Icon disappears when I add a new dynamic Node to the tree.  here's my code.


Thanks for the help. 






mar10

unread,
Aug 3, 2012, 2:58:59 PM8/3/12
to dyna...@googlegroups.com
i guess adding a nodes re-renders, so the classes are re-crated.
you could try to set the 'node.data.addClass' :

    $("#btn1").click(function(e){
        var node $("#tree").dynatree("getActiveNode");
        $(node.span).addClass("custom1");
        node.data.addClass "custom1";
    });

suresh2

unread,
Aug 6, 2012, 5:20:23 AM8/6/12
to dyna...@googlegroups.com
Thanks that solved my Problem. Hope it won't create any performance issue. 

Ann Gledson

unread,
Nov 6, 2014, 4:44:41 AM11/6/14
to dyna...@googlegroups.com
Hi,

I have a further problem relating to the above question. When removing a class, I believe this can only be done via the jquery method: 
$(node.span).removeClass("custom1")  and there is no associated node.data.removeClass("custom1") method, similar to the way the above problem was solved.

When I remove a class from a node, it re-appears again (presumably when the node is re-rendered.  
In my case I have an 'ignore-node' class which (using CSS) displays with a strike-through of the title. When I try to remove the ignore, it works temporarily, but then the class/strikethrough re-appears when I expand / collapse the node.

I have added to the fiddle code by suresh2 above (correcting the issue that they originally raised), and adding a button to 'Remove Icon from active node'. This re-creates my problem.


Hope someone can help.

Ann

mar10

unread,
Nov 6, 2014, 3:49:09 PM11/6/14
to dyna...@googlegroups.com
When adding a class, you correctly added it to node.data, so it also is re-applied when the node is redrawn:

        $(node.span).addClass("custom1");
        node.data.addClass = "custom1";

similarly you should remove both:

        $(node.span).removeClass("custom1");
        node.data.addClass = "";

Ann Gledson

unread,
Nov 9, 2014, 10:38:56 AM11/9/14
to dyna...@googlegroups.com
Ah yes, seems obvious now!! 
Thanks.
Reply all
Reply to author
Forward
0 new messages