How to get selected row index in Kendo grid if cell selection has set?

1 Answer 11522 Views
Grid
Toron
Top achievements
Rank 1
Toron asked on 20 Mar 2013, 07:19 PM
I'm working on a project using MVC 3 and kendo controls. I have a Kendo grid that has set to have GridSelectionType.Row,  and I can get the correct selected row index by using index() function.

Code in .cshtml:
.Selectable(selectable => selectable.Enabled(true).Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Row))

Code in javascript file:
var grid = $('#MyGrid').data("kendoGrid");
var selectedRow = grid.select();
var selectedRowIndex = selectedRow.index();

I also have another Kendo grid and this grid has set to have Cell selection. I can get correct selected cell index by cellIndex() function,  but I cannot get the correct selected row index by using index() function.

Code in .cshtml:
.Selectable(selectable => selectable.Enabled(true).Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Cell))

Code in javascript file:
var grid = $('#MyGrid').data("kendoGrid");
var selectedRow = grid.select();
var selectedRowIndex = selectedRow.index();             // incorrect selected row index returned
var selectedCellIndex = grid.cellIndex(grid.select());  // correct selected cell index returned

Please help. How can I get selected row index on Kendo grid if it is in cell selection type?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 22 Mar 2013, 01:08 PM
Hi Toron,

 
Basically in current case when the GridSelectionMode is "Multiple" and the GridSelectionType is "Cell" the select method return array of selected grid cells. For example you can iterate over the array to get the closest "tr" element index for each cell.

e.g.:

var grid = $("#Grid").data("kendoGrid");
currentSelection = grid.select();
selectedRows = [];
currentSelection.each(function () {
    var currentRowIndex = $(this).closest("tr").index();
    if (selectedRows.indexOf(currentRowIndex) == -1) {
        selectedRows.push(currentRowIndex);
    }
})
//now the selectedRows array contains all selected rows indexes
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Pallavi
Top achievements
Rank 1
commented on 27 Nov 2019, 12:13 PM


How to pass rowIndex in the kendo-Grid-Column-Group?
Angel Petrov
Telerik team
commented on 29 Nov 2019, 11:37 AM

Hello Pallavi,

I am difficulties understanding the question. Can you please elaborate in detail on what exactly are you trying to achieve? If you can additionally share with us some sample code snippets that would be great.

Regards,
Angel Petrov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Pallavi
Top achievements
Rank 1
commented on 29 Nov 2019, 12:24 PM

Hi ,

I need to pass row index to array DetailedReportGridData[0] instead of 0 to get categoryListArr(which our sub array.) related to that row. 

<kendo-grid [data]="DetailedReportGridData">
    <kendo-grid-column field="fName" title="fName" width="150">
        <ng-template kendoGridFilterMenuTemplate let-column="column">
        </ng-template>
    </kendo-grid-column>
    <kendo-grid-column field="Lname" title="Lname">
        <<ng-template kendoGridFilterMenuTemplate let-column="column">
            </ng-template>
    </kendo-grid-column>
    <kendo-grid-column-group *ngFor="let category of DetailedReportGridData[0].categorylistArr; let j= index "
        title="{{category.categoryName}}">
        <kendo-grid-column field="{{category.compliant}}" title="COMPLIant" [width]="150" [filterable]="false">
            <ng-template kendoGridCellTemplate let-column="column" let-row="row" let-columnIndex="columnIndex"
                let-rowIndex="rowIndex">
                {{category.compliant}}
            </ng-template>
        </kendo-grid-column>
        <kendo-grid-column field="{{category.noncompliant}}" title="NONCOMPLIant" [width]="150" [filterable]="false">
            <ng-template kendoGridCellTemplate let-column="column" let-row="row" let-columnIndex="columnIndex"
                let-rowIndex="rowIndex">
                {{category.compliant}}
            </ng-template>
        </kendo-grid-column>
    </kendo-grid-column-group>
</kendo-grid>

Dimiter Topalov
Telerik team
commented on 03 Dec 2019, 11:23 AM

Hello Pallavi,

This forum thread is discussing a scenario involving a Kendo UI for jQuery Grid.

Can you please open a separate thread choosing the correct product (Kendo UI for Angular 2+ Grid) that will be addressed accordingly by the team responsible for creating and supporting the Kendo UI for Angular suite?

Regards,
Dimiter Topalov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Toron
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or