Get selected node databound item id

5 posts, 1 answers
  1. Andrei
    Andrei avatar
    2 posts
    Member since:
    Mar 2012

    Posted 24 Jul 2012 Link to this post

    I have a treeview build with load on demand from a datasource that is a list of items, every item has an id. I want to send to the server using ajax the id of the selected item in the tree.
    --- View code ---
    @(Html.Kendo().TreeView()
            .Name("treeview")
            .DataTextField("Name")
            .DataSource(dataSource => dataSource
                .Read(read => read
                    .Action("OmanagerItems", "TaskManager")
                )
            )
            .Events(events => events
                .Select("onSelect")
                .Expand("onExpand"))
        )
    function onSelect(e) {
        var itemId = e.node.getAttribute("data-uid");
       // this is where i want to get the id of the selected item
    }
     
    // here i want to tell the server that i'm working on a task
    function changeWorkingStatus(docId) {
        $.ajax({
            url: "/TaskManager/ChangeWorkingStatus",
            type: "POST",
            success: function (data) {
                updateInterface(data.IsWorking);
            }
        });
    }

    I'll appreciate any help, thank you.
  2. Answer
    Constantine
    Constantine avatar
    9 posts
    Member since:
    Apr 2012

    Posted 24 Jul 2012 Link to this post

    Try this:

    var data = $('treeview').data('kendoTreeView').dataItem(e.node);
     
    console.log(data.id);
  3. Kendo UI is VS 2017 Ready
  4. Andrei
    Andrei avatar
    2 posts
    Member since:
    Mar 2012

    Posted 25 Jul 2012 Link to this post

    Thank you! Exactly what I needed!
  5. Nathan
    Nathan avatar
    23 posts
    Member since:
    Jul 2012

    Posted 25 Mar 2014 in reply to Constantine Link to this post

    This is somewhat close to what I'm trying to accomplish.  I'm trying to create a treeview and when you select a node, it will call an action in the controller.  The screen refreshes with data in a grid.  I just need to figure out how when you select a node, it calls the action in the controller.  This isn't necessarily an ajax call for a view will be return with the appropriate data that was sent in (node Id).
  6. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 19 Oct Link to this post

    Hello,

    This post is to prevent any confusion with regard to getting a proper reference to the TreeView. The correct selector to be used in the example Constantine posted is "#treeview" as the widget will be rendered with id="treeview" : 
    var data = $('#treeview').data('kendoTreeView').dataItem(e.node);


    Regards,
    Ivan Danchev
    Telerik by Progress
     
    Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
     
Back to Top
Kendo UI is VS 2017 Ready