Gunaseelan Gunaseelan - 1 year ago 411
Javascript Question

How do I get the index and data of a selected row in a grouped Kendo grid

I'm trying to access the row index like this:

var grid = $("#grid").data("kendoGrid");

I have added my code in this jsfiddle link. This code worked in my system, I dont know why
method isn't invoked in jsfiddle, But that is not actual question.

Here while clicking on last row's cancel button alert message will says index as 8, But the actual index is 4. every button gives me wrong index only.

Answer Source

You're using a very old version of Kendo UI in your fiddle, so selecting didn't work either. The reason it didn't find deleteRecord is that you set your fiddle to wrap in window.onLoad, which happens after document.ready.

Regarding the row index: you need to determine the index relative to the grid's data rows (if you simply get the index of the selected row, it will count the grouping rows as well; the same would happen for detail rows if you had any), so you can use grid.items() like this:

var grid = $("#grid").data("kendoGrid");        
var dataRows = grid.items();
var rowIndex = dataRows.index(;

See demo here.

If what you're really interested in is accessing the data of the selected row, you should use something like this (note that all of this is assuming your grid is set to cell or single row selection):

var tr ="tr");
var dataItem = grid.dataItem(tr);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download