1

How do I programatically select an Angular Kendo Grid row? Not by user interface, but by a selection functioin. Eg, is there way to programatically select the third row?

Currently using Angular 10

Resource:

https://www.telerik.com/kendo-angular-ui/components/grid/

1
  • were you able to test the solution ? Commented Jul 20, 2020 at 0:03

2 Answers 2

1

Solution 1:

Kendo provide a way to Programmatically select the row. you can use the event rowSelected

It is Defines a Boolean function that is executed for each data row in the component and it determines whether the row will be selected.

<kendo-grid
    [data]="gridData"
    [height]="500"
    [selectable]="true"
    [rowSelected]="isRowSelected"
>

public gridData: any[] = products;
public mySelection: any[] = [1, 3, 5];

// Use an arrow function to capture the 'this' execution context of the class.
public isRowSelected = (e: RowArgs) => this.mySelection.indexOf(e.dataItem.ProductID) >= 0;

Here is the link with running demo and good explaination using Angular 10.

Kendo-grid: Select Row Programatically using Angular

https://www.telerik.com/kendo-angular-ui/components/grid/selection/#toc-setting-the-selected-rows

Solution 2:

You can make use of selectionKeys to set it dynamically and later any one can change selection but your question does not mention preserving the selection so this link should end the discussion

https://stackblitz.com/edit/angular-10-decatechlabs

Sign up to request clarification or add additional context in comments.

5 Comments

hi Sean, please also post your answer, in these two links, for some reason, no one provides a updated answer, thanks stackoverflow.com/questions/43581367/… stackoverflow.com/questions/40051846/…
the other question is, it gets stuck on my rows, how can I modify so its not stuck, I want it to be set once, and then lets the user keep choosing items in the multi selection grid, its crucial the data selection does not get stuck
@marksmith542 ok i will look into your other questions. to make sure i understand it correctly when you mean stuck can you explain it ? do you mean that on first page load you want the rows to pre-selected only . can you explain properly so i don't waste your time here and there and guide you correctly.
when I mean stuck, I cannot deselect the rows using in the code above, in the user interface
this should work for your stuck situation . you can make use of selectionKeys to set it dynamically and later any one can change selection but your question does not mention preserving the selection so this link should end the discussion. stackblitz.com/edit/angular-10-decatechlabs
1

You need to provide the input [selectedKeys] to the kendo grid to which you will have to provide an array of indices of the rows you want to be selected when the grid is loaded. If at a later point of time you want to change or update the selected rows then you can just update the array of selectedKeys accordingly.

Kendo has provided a demo here- https://www.telerik.com/kendo-angular-ui/components/grid/selection/#toc-during-data-operations

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.