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

I am trying to access the row index as follows:

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

I added the code in jsfiddle . This code worked on my system, I do not know why the deleteRecord() method is not called in jsfiddle, but this is not a question.

When you click on the warning message with the last button to cancel the line, index 8 will be indicated, but the actual index is 4 . each button gives me the wrong index.

+6
source share
3 answers

You are using a very old version of the Kendo user interface in your violin, so the selection did not help either. The reason he did not find deleteRecord is because you set your script to window.onLoad , which happens after document.ready .

Regarding the row index: you need to define the index in relation to the grid data rows (if you just get the index of the selected row, it will also count grouping rows, the same will happen for rows with detailed information if you had any), so you can use grid.items() as follows:

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

See the demo here .

If you are really interested in accessing the data of the selected row, you should use something like this (note that all this assumes that your grid is set to select a cell or a single row):

 var tr = grid.select().closest("tr"); var dataItem = grid.dataItem(tr); 
+13
source

Thus, it could be just my kendo configuration, but the way to access the row index of the selected records was like this:

 var archGrid = $("#archiveRecords").data("kendoGrid"); var impGrid = $("#importedRecords").data("kendoGrid"); var archRow = archGrid.select(); var impRow = impGrid.select(); var archRowIndex = archRow[0].rowIndex; var impRowIndex = impRow[0].rowIndex; 

So, once I set the index in my variables, I had to set it by adding and removing CSS classes to my specified lines. I had to use the element.find method to do this as follows:

 if (condition1) { impRow.removeClass('k-state-selected'); $('#importedRecords').data('kendoGrid').element.find('tbody tr:eq(' + archRowIndex + ')').addClass('k-state-selected'); } else if (condition2){ archRow.removeClass('k-state-selected'); $('#archiveRecords').data('kendoGrid').element.find('tbody tr:eq(' + impRowIndex + ')').addClass('k-state-selected'); } 

Just publish because I have been looking for a long time how to make a given string an index of a string. Good luck

+1
source

Below the codes you will get the row index as well as the column index in the kendo grid I hope this will be useful

 var grid = $("#kendogridid").data("kendoGrid"); var row = $(this).closest("tr"); var rowIdx = $("tr", grid).index(row); var colIdx = $("td", row).index(this); 
0
source

All Articles