Search code examples
kendo-uikendo-treeview

Get updated Kendo Tree View data source


I am showing the tree view with a datasource but after dragging and dropping there will be changes and I have to get that changed new datasource. How do I do that?

$.ajax({
         type: "POST",
         url: "TestMenu.aspx/GetMenuData",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (data) {
         $("#treeview").kendoTreeView({
                 dragAndDrop: true,
                 dataSource: $.parseJSON(data.d)
             });
          }
         });

Solution

  • So, I finally accomplished the task. Posting answer for anyone who's looking for the same answer as I was.
    Changed the call to:

           $.ajax({
               type: "POST",
                url: "TestMenu.aspx/GetMenuData",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    $("#treeview").kendoTreeView({
                        dragAndDrop: true,
                        dataSource: $.parseJSON(data.d)
                    }).data("kendoTreeView");
                }
            });
    

    Then to get the updated data source:

    var treeviewDataSource = $("#treeview").data("kendoTreeView").dataSource.view();