You can select a row manually, as shown below, I tried Kendo in my grid, but this may require some polishing.
Define some required variables : (specify the missing variables from the code below)
rowIndex : number =0; isSelectedRowChanged: boolean = false; selectedItem : any;
Define a Function to set the selected line as shown below:
public SetSelectedRow(index: number, isManualSelection, isSelected, isCellClick) { var grid = this.el.nativeElement.getElementsByClassName('k-grid-content')[0]; var rows = grid.getElementsByTagName('tr'); let dataRowIndex = -1; let selectedRow = grid.getElementsByClassName('k-state-selected')[0]; for (let i = 0; i < rows.length; i++) { if (rows[i].className.indexOf("k-grouping-row") < 0 && rows[i].className.indexOf("k-group-footer") < 0) { if (isManualSelection) { this.rowIndex = 1; if (selectedRow != null) { selectedRow.className = String(selectedRow.className).replace(" k-state-selected", '').replace("k-state-selected", ''); } if (rows[i].className.indexOf("k-state-selected") < 0) { rows[i].click(); } //Set selectedItem for (let k = 0; k < rows[i].children.length; k++) { if (rows[i].children[k].className.indexOf("k-group-cell") < 0 && rows[i].children[k].children[0] != null) { rows[i].children[k].children[0].click(); break; } } break; } else { if (this.isSelectedRowChanged) { this.rowIndex = index + 1; return; } if (selectedRow == null) { //Set selectedItem rows[i].className = rows[i].className + " k-state-selected"; for (let k = 0; k < rows[i].children.length; k++) { if (rows[i].children[k].className.indexOf("k-group-cell") < 0 && rows[i].children[k].children[0] != null) { rows[i].children[k].children[0].click(); break; } } break; } else { dataRowIndex++; if (!this.isSelectedRowChanged) { if (isSelected && !isCellClick) { selectedRow.click(); } break; } else { this.rowIndex = dataRowIndex + 1; } } } } } }
The call function below to set the first row selected after assigning the data source to the grid:
setTimeout(() => { this.rowIndex = 0; this.SetSelectedRow(0, true, false, false); }, 200);
Write the function below in the Row Select Change Event :
public OnSelection_Changed(item: any): void { if (!item.selected) { this.SetSelectedRow(item.index, false, true, false); } else { this.SetSelectedRow(item.index, false, false, false); } }
Also define the Cell Click event :
OnCellClick(dataItem, rowIndex, columnIndex) { if (this.selectedItem != dataItem) { this.isSelectedRowChanged = true; this.selectedItem = dataItem; } else { this.isSelectedRowChanged = false; } }