jQuery UI Widgets Forums Navigation Tree How To Add Items Programatically?

This topic contains 3 replies, has 2 voices, and was last updated by  Peter Stoev 12 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • How To Add Items Programatically? #2549

    eric
    Member

    Can someone please post an example of how to add tree items through code – not via static source?

    The docs are really unclear around what an “element” is defined as:

    $(‘#jqxTree’).jqxTree(‘addTo’, element, parentElement);

    How do you reference a specific element by id?

    Is this the appropriate way to add a root level element?
    $(‘#jqxTree’).jqxTree(‘addTo’, { label: “top level”, id: “1” });

    Thanks.

    How To Add Items Programatically? #2550

    Peter Stoev
    Keymaster

    Hi Eric,

    To add an item programmatically, you can do the following:

    1. Add item to the Tree:

    $('#jqxTree').jqxTree('addTo', { label: 'Item' });

    2. Add a sub item to a specific tree item:

    var treeItems = $("#jqxTree").jqxTree('getItems');
    var firstItem = treeItems[0];
    var firstItemElement = firstItem.element;
    $('#jqxTree').jqxTree('addTo', { label: 'Item' }, firstItemElement);

    3. Add a sub item to a specific tree item by using the id of the item’s associated element:

    var elementByID = $('#jqxTree').find("#home")[0];
    $('#jqxTree').jqxTree('addTo', { label: 'Item' }, elementByID);

    ‘home’ in the above code is the ID of a LI element.

    <li id='home'>Home</li>

    Hope this helps.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    How To Add Items Programatically? #2564

    eric
    Member

    How do add an element to the tree with an ‘id’ value?

    In your example you refer to id=’home’ …. but how do you add that to the tree?

    var elementByID = $(‘#jqxTree’).find(“#home”)[0];
    $(‘#jqxTree’).jqxTree(‘addTo’, { label: ‘Item’ }, elementByID);

    If I do:

    $(‘#jqxTree’).jqxTree(‘addTo’, { label: “Sports”, id: “sports” });

    and then try to find with:

    var elementByID = $(‘#jqxTree’).find(“#sports”)[0];

    it is not resolved.

    Please advise.

    Thanks.

    How To Add Items Programatically? #2565

    Peter Stoev
    Keymaster

    Hi Eric,

    In my example, I was adding a new tree item as a sub-item of a tree item with id=”home”

    To add a new item which has a specific ID, use this code:

    $('#jqxTree').jqxTree('addTo', { html: "<span style='font-weight: bold;' id='myItem'>Item</span>" });

    Best Regards,
    Peter Stoev

    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.