13 Answers, 1 is accepted
0

Ranjit
Top achievements
Rank 1
answered on 23 Aug 2012, 08:10 PM
I figured out a method to do this, although it's not a very clean work around.
here is the code in case anyone is interested... I am still curious as to whether this is possible without manually walking through the child collection.
function SetSelectedAccountByID(id) {
var listView = $("#Accounts-listview").data("kendoListView");
var children = listView.element.children();
var index = 0;
for (var x = 0; x < children.length; x++) {
if (listView.element.children()[x].id == id) {
index = x;
};
};
// selects first list view item
listView.select(children[index]);
};
here is the code in case anyone is interested... I am still curious as to whether this is possible without manually walking through the child collection.
function SetSelectedAccountByID(id) {
var listView = $("#Accounts-listview").data("kendoListView");
var children = listView.element.children();
var index = 0;
for (var x = 0; x < children.length; x++) {
if (listView.element.children()[x].id == id) {
index = x;
};
};
// selects first list view item
listView.select(children[index]);
};
0

Daniel
Top achievements
Rank 1
answered on 01 Sep 2014, 08:45 AM
Why is an easy task as this one so difficult in Kendo?
This has to be a built-in function!
Regards,
Daniel
This has to be a built-in function!
Regards,
Daniel
0
Hello Daniel,
By design the selection is performed over DOM elements. You could use the get() method of the dataSource to retrieve the exact dataItem via it's ID and then retrieve the DOM element via the uid attribute.
Let me know if I could provide further assistance.
Regards,
Dimiter Madjarov
Telerik
By design the selection is performed over DOM elements. You could use the get() method of the dataSource to retrieve the exact dataItem via it's ID and then retrieve the DOM element via the uid attribute.
Let me know if I could provide further assistance.
Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Daniel
Top achievements
Rank 1
answered on 01 Sep 2014, 09:51 AM
Hello Dimiter,
I think this tasks are daily business for most developers. Why we are buying libraries such as Kendo? We don't want to use "Low Level API's" for basic tasks.
One more point is, that Kendo is here and there a little bit inconsistent in its API.
E.g. TreeView has a method .findByUid(). Why not ListView too!?
Why don't have both (and other datasource) controls a method like .findById() ?
Regards,
Daniel
I think this tasks are daily business for most developers. Why we are buying libraries such as Kendo? We don't want to use "Low Level API's" for basic tasks.
One more point is, that Kendo is here and there a little bit inconsistent in its API.
E.g. TreeView has a method .findByUid(). Why not ListView too!?
Why don't have both (and other datasource) controls a method like .findById() ?
Regards,
Daniel
0
Hello Daniel,
All widgets that internally use a dataSource can access it and invoke it's getByUid method.
E.g.
If you consider that we should add more methods to the ListView API, you could post this suggestion in our UserVoice portal. If the idea is popular among our users, we will consider to implement it in future releases.
Regards,
Dimiter Madjarov
Telerik
All widgets that internally use a dataSource can access it and invoke it's getByUid method.
E.g.
var
lv = $(
"#listview"
).data(
"kendoListView"
);
lv.dataSource.getByUid(...);
If you consider that we should add more methods to the ListView API, you could post this suggestion in our UserVoice portal. If the idea is popular among our users, we will consider to implement it in future releases.
Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Daniel
Top achievements
Rank 1
answered on 01 Sep 2014, 12:33 PM
You are correct, but I'm looking for the respective ListView-Item (for selecting)!
Following returns the corresponding data item. I'm looking for the list-view item!
Now I do this:
I'm missing a method like in TreeView to do at least this:
.findByUid doesn't exist on ListView, but on TreeView (this is inconsistent)
I think this should be (built-in Kendo):
Regards
Daniel
PS: Be aware of using Uid and Id in my snippets
Following returns the corresponding data item. I'm looking for the list-view item!
lv.dataSource.getByUid(...);
Now I do this:
var
listViewItem = lv.element.children(
"[data-uid='"
+ lv.dataSource.get(id).uid +
"']"
);
lv.select(listViewItem);
I'm missing a method like in TreeView to do at least this:
lv.select(lv.findByUid(lv.dataSource.get(id).uid));
.findByUid doesn't exist on ListView, but on TreeView (this is inconsistent)
I think this should be (built-in Kendo):
lv.select(lv.findById(id));
Regards
Daniel
PS: Be aware of using Uid and Id in my snippets
0
Hi Daniel,
Yes, this approach is correct for retrieving the corresponding DOM element via id and then selecting it.
Thank you for the suggestion about the findByUid method. As stated previously, I would recommend to also post it in our User Voice portal.
Regards,
Dimiter Madjarov
Telerik
Yes, this approach is correct for retrieving the corresponding DOM element via id and then selecting it.
Thank you for the suggestion about the findByUid method. As stated previously, I would recommend to also post it in our User Voice portal.
Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Peter
Top achievements
Rank 1
answered on 15 Aug 2016, 08:28 AM
The code required to select a ListView as provided here is just outrageously dumb. I'm sorry.
Please don't ask us to vote for a feature that common sense already requires.
Kendo should fix the API, as sensibly described in the posts here, of their own accord.
It is your reputation, and the quality of your product. It is not our responsibility to beg you to fix it.
0
Hello Peter,
The reasoning behind this approach is that the ListView selection relies only on DOM elements. If any item should be retrieved via it's ID, this should be achieved through the DataSource API.
Regards,Dimiter Madjarov
Telerik by Progress
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
0

Mark
Top achievements
Rank 1
Veteran
answered on 03 Aug 2017, 09:51 PM
This works for me:
// selects a list view item
function
selectListViewItem(selector, id) {
var
listView = $(selector).data(
"kendoListView"
);
var
listViewItem = listView.element.children(
"[data-uid='"
+ listView.dataSource.get(id).uid +
"']"
);
listView.select(listViewItem);
}
0

Mark
Top achievements
Rank 1
Veteran
answered on 03 Aug 2017, 09:56 PM
The issue I keep running into is selecting an item (e.g. one just added) after refreshing the datasource. I have to select the new item in the dataBound event but don't have a clean way of passing the model's id of the new one just added to this event.
0
Hello,
It is possible to select the new item as handle save event of ListView and access uid in it.
Here, you can find a sample, which demonstrates this approach.
Regards,
Milena
Progress Telerik
It is possible to select the new item as handle save event of ListView and access uid in it.
Here, you can find a sample, which demonstrates this approach.
Regards,
Milena
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0

Mark
Top achievements
Rank 1
Veteran
answered on 08 Aug 2017, 03:30 PM
Interesting, thanks!
-mb