Reputation: 29
Kendo UI experts Please help me..
I am new to Kendo ui. I want to return id of Selected node in kendo treeview in my code. but it is returning only same node.
On selecting Node i want to return id of selected Node to my code, and in Code i am returning child elements of that node.
is there any simple way of doing it??
Thanks in advance..
My Code
<script src="~/Scripts/kendo.treeview.min.js"></script>
<script>
homogeneous = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "@Url.Action("datasourcefortree", "Home")",
type: "POST",
dataType: "json"
}
},
schema: {
model: {
id: "ResourceID",
hasChildren: true
}
}
});
$("#treeview").kendoTreeView({
dataSource: homogeneous,
dataTextField: "Resource"
});
</script>
and code of datasourcefortree method of homecontroller
[HttpPost]
public JsonResult datasourcefortree(int? NodeID)
{
FNHSessionManager sessionManager = new FNHSessionManager(_connString, FNHSessionManager.DatabaseType.MsSql);
FNHRepository repository = new FNHRepository(sessionManager);
int nodevalue = 1;
if (NodeID == null)
{
ResourceMaster tree = repository.RetrieveById(nodevalue);
List node = new List{
new ResourceMaster
{
ResourceID = tree.ResourceID,
Resource=tree.Resource
}
};
return Json(node, JsonRequestBehavior.AllowGet);
}
else
{
if (NodeID.HasValue)
{
nodevalue = NodeID.Value;
IList childtreenode = repository.GetAllRecord(nodevalue);
return Json(childtreenode, JsonRequestBehavior.AllowGet);
}
return (null);
}
}
Upvotes: 2
Views: 8571
Reputation: 21
Try this:
$("#treeview").kendoTreeView({
select: function(e) {
alert($("#treeview").getKendoTreeView().dataItem(e.node).ResourceID);
},
//... other code
});
Upvotes: 2