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

Getting Index of the selected/clicked row in Angular Grid

3 Answers 1536 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 22 Nov 2016, 11:31 AM

Hello,
I am looking at following example and I would like to get the index of the clicked item, how would I do that?

http://dojo.telerik.com/@korchev/amaK

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 22 Nov 2016, 02:19 PM
Hi Savas,

I assume that you need the Kendo UI Data Source zero-based index. To get the dataItem index, you can loop over the data source data() and find the index when it matches the dataItem EmployeeID in our case. To verify that this is the correct index, you can double-check with the at() method:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-at

I have updated the provided demo to illustrate:

http://dojo.telerik.com/OBakO

Regards,
Alex Hajigeorgieva
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
James
Top achievements
Rank 1
answered on 23 Nov 2016, 09:47 AM
Thanks Alex, I am looping over the datasource right now, but I was hoping to avoid looping over as datasource could be large, instead I thought there is some property like $index or something which can be used to determine the index of clicked row in the command
0
Alex Hajigeorgieva
Telerik team
answered on 23 Nov 2016, 11:58 AM
Hi Savas,

Actually, there is a method revealed by the public API of the Kendo UI Data Source that can be used for more clarity indexOf() that seems to have eluded me in my original response:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-indexOf

However, internally, it does the same thing as the filter() array method - it loops over the dataItems:

https://github.com/telerik/kendo-ui-core/blob/master/src/kendo.data.js#L251-L262

Updated Dojo demo: http://dojo.telerik.com/OBakO/2

I would like to address the fact that in an array, the complexity remains unchanged - we need to loop over each record to get to it - worse case scenario - linear time.

It would be very helpful if you elaborate on the need to get the Kendo UI Data Source index, perhaps there is another way to accomplish your requirement which I fail to see from my current point of view. Are you looking for the index of the data source that was originally assigned to the data, is it the row index of the current page, filter, group, etc. Knowing the exact requirements will greatly aid me in proposing a suitable solution.

Look forward to your response.

Regards,
Alex Hajigeorgieva
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
James
Top achievements
Rank 1
Share this question
or