Please suggest me a way to load the nodes of a tree view dynamically and also add nodes to the tree view and to save those nodes in the data base tables.........
I can describe our method for delayed loading.
First, you must fill root nodes. Each node must contain a fake node with "Loading..." text. You must handle "expand" event. In this method, you can make $.post or another query to your webservice/database. Use will see "Loading" fake node while this query processing. Also, you can use node template for storing some information about node. Look to our template, for example (and see attach for screenshot of final treeview):
Or you can also (with the latest kendo ui version) use the hierarchical datasource.
You will need a server method that returns the child nodes.
The javascript code would look like this:
$('#TreeView').kendoTreeView({
dataSource: {
transport: {
read: {
url: 'YOURURLHERE'
}
},
schema: {
model: {
id: 'ANIDPROPERTY',
hasChildren: 'PROPERTY'
}
}
},
dataTextField: 'TEXTPROPERTY'
});
a) The value you set as the model id will be send to the server method, so if you set for example as id 'Group', in the server method you must have a paramater with the same name, or look for a variable (if you use php) with that name to get the children nodes. b) In the hasChildren, you will set the property that the tree should use to know if the node is expandable or not (true/false).
To add nodes you should make use of the .add or .append javascript function of the treeview.
$('#TreeView').data('kendoTreeView').append({text: "new node"});
The function accepts a second parameter used to specify that the new node should be appended as a children of the node you pass to the function (second parameter). If you do not set a second parameter it will be created in the first level.