As mentionned, there are two SlickGrid selection models: cell selection and row selection.
If you want to use both, what I suggest is to create a column which contains the index of the row, like in Excel. This one will be used to do row selection. If we click on a cell from this column, we switch the selection model by using setSelectionModel
from SlickGrid. To take these changes into account, you have to call invalidate
.
Here is a partial example where OnClick
method is binded to (onClick)
:
angularGrid: AngularGridInstance;
gridOptions: GridOption;
angularGridReady(grid: AngularGridInstance) {
this.angularGrid = grid;
}
ngOnInit(): void {
this.gridOptions = {
enableCellNavigation: true,
//enableRowSelection: true, // If set to true, it disable cells selection
enableExcelCopyBuffer: true // Enable copy but also cells selection
};
}
onClick(event: Event, args: any) {
if (args.cell != 0) { // Click NOT in index column
if (this.angularGrid.slickGrid.getSelectionModel() instanceof SlickRowSelectionModel) {
this.angularGrid.slickGrid.setSelectionModel(new SlickCellSelectionModel());
this.angularGrid.slickGrid.invalidate();
}
} else {
if (this.angularGrid.slickGrid.getSelectionModel() instanceof SlickCellSelectionModel) {
this.angularGrid.slickGrid.setSelectionModel(new SlickRowSelectionModel());
this.angularGrid.slickGrid.invalidate();
}
}
}