This is a migrated thread and some comments may be shown as answers.

Treeview - load dynamic multiple levels of nodes using remote binding

1 Answer 1236 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Naga
Top achievements
Rank 1
Naga asked on 24 Aug 2016, 03:58 PM
I am trying to implement multilevel lazy loading treeview. We are not sure of how many levels of nodes will be there in the treeview.
1. ) How can i implement multiple levels of nodes ?  i have X number of items and it is not possible for me to provide  children always. 
2. )  while creating my treeview data model i have an attribute "RANK" in the model. How do i get value of RANK for expanded node so that i can pass it as input while calling service to load child node? 
For URL i need to add RANK as parameter. When i used   url: function (options) { })  i am only getting ID value in options but not the RANK. 
Below is the code i implemented for two levels.
Please help. If possible please provide an example.
Thanks in advance.

    <div id="trVwScanOrg" ></div>

    $(document).ready(function () {
        TreeviewDataBind();
 });


    function TreeviewDataBind() {
var SecondLevel= {
            transport: {
                read: {
                    url: function (options) {


                return kendo.format(MVC URL + parameters in querystring);

                    },
                    type: "get",
                    dataType: "json"
                }
            },
            schema: {
                model: {
                    id: "ID",
                    hasChildren: "HasChildren",
                    children: NextLevelItems,
                    Name: "Name"
                }
            }
        };

        var FirstLevel= new kendo.data.HierarchicalDataSource({

            transport: {
                read: {
                    url: MVC URL + parameters in querystring
                    type: "get",
                    dataType: "json"
                }
            },
            schema: {
                model: {
                    hasChildren: "HasChildren",
                    id: "ID",
                    children: SecondLevel,
                    Name: "Name"
                }
            }
        });

        var trVwScanOrg = $("#trVwScanOrg").kendoTreeView({
            dataSource: FirstLevel,
            dataTextField: ["Name"]

        });
    }

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Aug 2016, 10:26 AM
Hello Naga,

Apologies for the delayed response.

Regarding the two questions:

1) How to implement multiple levels of nodes with X number of items: 
 
The Hierarchical DataSource supports multiple levels of nodes with X number of items.
 
I made examples demonstrating implementation with N-level nesting, and with fixed number of levels:

N-level nesting:

http://dojo.telerik.com/omUHe

Fixed number:

http://dojo.telerik.com/OfIGa

2) How to get the value of RANK for expanded node:

I can suggest using the dataItem method of the Kendo UI TreeView on its expand event, to retrieve the value of the RANK attribute:

http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#methods-dataItem

http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#events-expand

I hope these examples will help you to achieve the desired result.

Regards,
Stefan
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
TreeView
Asked by
Naga
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or