jQWidgets Forums

jQuery UI Widgets Forums Navigation Tree addTo Method Specifics

This topic contains 3 replies, has 2 voices, and was last updated by  Dimitar 11 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • addTo Method Specifics #29736

    aoverton07
    Participant

    When adding an item to a section of the Tree using the addTo method, do all the items in that section of the tree get redrawn?

    When I use the addTo method, everything works fine but it seems that I have lost my click handlers attached to the items in the section where I added the new item. It would make sense that I lost the click handler if they all got redrawn, I can fix this by restating the handler just wanted to see if this was the culprit, or if it was something else in my code…..

    addTo Method Specifics #29808

    Dimitar
    Participant

    Hello aoverton07,

    Please provide us with a sample code which we may test for the reported issue.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    addTo Method Specifics #29853

    aoverton07
    Participant
    $(document).ready(function () {
    $("#treeTest").jqxTree({ theme: 'classic' });
    $("#clickSection .clickItem").on('click', function(){
    alert('clicked');
    });
    $("#addItem").on('click', function(){
    var selectedItem = $("#treeTest").jqxTree('getSelectedItem');
    $("#treeTest").jqxTree('addAfter', { label: 'Nine' }, selectedItem.element);
    });
    });
    <div id="treeTest">
    <ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li id="clickSection">Four
    <ul id="addSection">
    <li class="clickItem">Six</li>
    <li class="clickItem">Seven</li>
    <li class="clickItem">Eight</li>
    </ul>
    </li>
    </ul>
    </div>
    <input type="button" id="addItem" value="ADD" />

    Select Item “Eight” then click the add button, notice the handler is gone 🙁

    addTo Method Specifics #29893

    Dimitar
    Participant

    Hi aoverton07,

    When the tree is re-rendered (e.g., when you call the addAfter method), custom event handlers are lost. This is a normal behaviour.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.