with the old telerik MVC extensions, i could do the following:
then i could use the following javascript to get the node value when a node is selected:
Now with Kendo, i don't see how to get the value of the selected node any longer. Any tips?
@(Html.Telerik().TreeView().Name("TreeView").HtmlAttributes(new { style = "white-space:normal;width:250px;" }).ClientEvents(events => events
.OnLoad("onLoad")
.OnSelect("onSelect")
)
.BindTo(Model.RootNode.ChildNodes, mappings =>
{
mappings.For<
DocReaderNode
>(binding => binding
.ItemDataBound((item, nd) =>
{
item.Text = nd.DocTitle;
item.Value = nd.DocUrl;
})
.Children(nd => nd.ChildNodes));
})
)
function
onSelect(e) {
var
t = $(
'#TreeView'
).data(
'kendoTreeView'
);
var
selVal = t.getItemValue(e.item) ;
}
6 Answers, 1 is accepted
0
Trent
Top achievements
Rank 1
answered on 10 Jul 2012, 06:44 AM
Hey Phil. Did you get an answer for this? I'm also porting from Telerik to Kendo and ran into the same issue.
Thanks!
Thanks!
0
Hello Phil, Trent,
Depending on your use case, you have two options:
Alex Gyoshev
the Telerik team
Depending on your use case, you have two options:
- Use HtmlAttributes to serialize arbitrary data, item.HtmlAttributes(new { data_foo = "bar" }), and access it through e.item.data("foo")
- Use the TreeViewItem.Id field, if the serialized data is an Id and will be used for fetching nodes from a remote datasource. This field will be introduced in the upcoming Q2 release this week.
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 12 Jul 2012, 06:28 PM
when you say 'release this week', do you mean the 2012.2.710 release that i just downloaded?
That release actually broke the way the treeview used to work entirely. The bindto(model, mapping => mapping.For ..... no longer exists. Your documentation still references it at
http://docs.kendoui.com/api/wrappers/aspnet-mvc/Kendo.Mvc.UI.Fluent/TreeViewBuilder
however. Not sure how to proceed with your currennt treeview.
Additionally, do you have an example with the treeviewitem.id field that you mention below?
That release actually broke the way the treeview used to work entirely. The bindto(model, mapping => mapping.For ..... no longer exists. Your documentation still references it at
http://docs.kendoui.com/api/wrappers/aspnet-mvc/Kendo.Mvc.UI.Fluent/TreeViewBuilder
however. Not sure how to proceed with your currennt treeview.
Additionally, do you have an example with the treeviewitem.id field that you mention below?
0
> The bindto(model, mapping => mapping.For ..... no longer exists.
Alex Gyoshev
the Telerik team
The method exists (as seen in the Intellisense), but when you have a syntax error in the lambda expression, the c# compiler assumes it has a different type -- and thus complains about the method.
There is no dedicated example that shows this, so here it goes:
.BindTo(new List<Employee> () {new Employee { FirstName = "Alex" }}, mappings => {
mappings.For<Employee>(binding => binding
.ItemDataBound((item, employee) =>
{
item.Text = employee.FirstName;
item.Id = "2";
}));
})
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 16 Jul 2012, 03:10 PM
Thanks for that, the problem that i was having was assuming there was a TreeViewItem 'value' property in kendo like there was in the Telerik extensions. Looks like that was taken out.
For some reason i can't get this ID value in the Select event. basically, my code is:
so nd and the t variables work fine, i see values in them via firebug no problem. The id and url values give me nothing at all though (I also changed your code above so that the item.Url value is populated. that value might work better for me more than Id anyways).
For some reason i can't get this ID value in the Select event. basically, my code is:
function onSelect(e) {
//var treeView = $("#kTreeView").data("kendoTreeView");
var nd = e.node;
var t = nd.textContent;
var v = nd.id;
var c = nd.url;
}
0
Accepted
See the dataItem method.
Greetings,
Alex Gyoshev
the Telerik team
Greetings,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!