Get the ID of a selected Item

8 posts, 0 answers
  1. Adam
    Adam avatar
    5 posts
    Member since:
    Feb 2012

    Posted 20 Jun 2012 Link to this post

    When I create the items in the panelbar, I am passing in an id like this:

    panelbar.append({text:m.text, id:m.id});

    I need a way to get this id back when an item is selected, but I can't figure out how to do it.

    Getting just the text isn't sufficient.

    Thanks,
    Adam
  2. Kamen Bundev
    Admin
    Kamen Bundev avatar
    1532 posts

    Posted 25 Jun 2012 Link to this post

    Hello Adam,

    If you create the items one by one like this, the ID is not used and not kept, however - you can create the Menu from a single JSON object, which you can save somewhere and then reference it on select. check this jsFiddle on how you can do it:


    Currently the ID can't be set through append options. However, when Hierarchical DataSource support arrives in the PanelBar, each item in the DataSource has unique ID, which can be retrieved and this will ease the usage a bit.

    Kind regards,
    Kamen Bundev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Christophla
    Christophla avatar
    28 posts
    Member since:
    Jul 2012

    Posted 08 Oct 2012 Link to this post

    Kamen,
       How can I go about doing the same thing for the panelbar?
  5. Kamen Bundev
    Admin
    Kamen Bundev avatar
    1532 posts

    Posted 10 Oct 2012 Link to this post

    Hi Christopher,

    Almost the same way:


    All the best,
    Kamen Bundev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Andre
    Andre avatar
    1 posts
    Member since:
    Apr 2013

    Posted 15 Sep 2013 Link to this post

    I have a Kendo dropdown list where you can select a menu.
    When you select a menu the menu gets displayed as a panelbar. When you click an
    item on the panelbar I get the value like in the example above and everything
    works. When I choose another menu from the dropdown list the correct menu loads
    but the onselect retrieves the value of the previous menu and not the current
    menu. Is there a way of retrieving the current menu value?

    My code:
    $.getJSON('/Clientapi/getHierarchyMenu',
            function(menu) {
                function onSelect(e) {
                var dataItem = this.dataItem(e.item.index());                  
                        drawNavMenu(dataItem.value)            
                }
     
                var data = menu.items
     
                $("#hierarchyMenu").kendoDropDownList({
                dataTextField : "text",
                dataValueField : "value",
                optionLabel : "Please Select a Menu",
                dataSource : data,
                select : onSelect
                })
     
            });
    }
     
    function drawNavMenu(id) {
        url = '/Clientapi/getMenu?id=' + id
        $.getJSON(url, function(data) {
        function onSelect(e) {
            var item = $(e.item)
            var panelElement = item.closest(".k-panelbar")
            var dataItem = this.options.dataSource
            var index = item.parentsUntil(panelElement, ".k-item").map(
                function() {
                return $(this).index();
                }).get().reverse();
     
            index.push(item.index());
     
            for ( var i = -1, len = index.length; ++i < len;) {
            dataItem = dataItem[index[i]];
            dataItem = i < len - 1 ? dataItem.items : dataItem;
            }
     
            alert("---> " + dataItem.value)
        }
     
        $("#treeview-left").kendoPanelBar({
            dataSource : data,
            select : onSelect
        });
        });
    }


    Thanks.
    Andre.
  7. Kamen Bundev
    Admin
    Kamen Bundev avatar
    1532 posts

    Posted 18 Sep 2013 Link to this post

    Hi Andre,

    I will need a bit more code in order to decide what is going wrong. Can you isolate the issue in a sample page and send it over? You can open a support ticket if you value the privacy.

    Regards,
    Kamen Bundev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Peter
    Peter avatar
    44 posts
    Member since:
    Jan 2014

    Posted 19 Mar 2014 Link to this post

    Further to this, is there a Hierarchical DataSource on the horizon for the PanelBar? (which would alleviate the need for this awesome code)
  9. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 21 Mar 2014 Link to this post

    Hi Peter,

    We don't have immediate plans for such support. Please vote for this item in our UserVoice portal - once it gathers enough votes we will include it in our development plans.

    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready