Hi Adam,
Greetings from Syncfusion.
Query: How do I specify a set of pre-selected rows on load by record or by primaryKey (NOT by index) on a grid?
To achieve your requirement we have used the dataBound event of EJ2 Grid.
In dataBound event we have taken the current rows using the getRows method and using the rows we have taken the rowData from the rows using the getRowInfo method of EJ2 Grid.
Based on the primarykey data we have taken the rowindex of the corresponding row and selected the rows using the selectRows method. We have attached the sample so please refer the sample for your reference.
Code Snippet:
|
app.component.ts
dataBound(args){
let rows = this.grid.getRows();
let selectRows = [];
for (let i = 0; i < rows.length; i++){
let rowInfo = this.grid.getRowInfo(rows[i]);
let primaryData = (rowInfo as any).rowData[this.grid.getPrimaryKeyFieldNames()[0]];
if( (primaryData > 10001 && primaryData < 10008) || (primaryData > 10013 && primaryData < 10016) ){
let rowIndex = parseInt(rowInfo.row.getAttribute('aria-rowindex'));
selectRows.push(rowIndex);
}
}
if(selectRows.length){
this.grid.selectRows(selectRows);
}
} |
If the above solution does not meet your requirement, then please share the below details
1. Share the Complete grid code sample.
2. Share the Syncfusion package version.
Regards,
Ajith G.