0

I just figured out (not documented?) that in Angular-slickgrid when you set enableExcelCopyBuffer flag to true, it allows you to select multiple cells. Nevertheless, it does not work when enableRowSelection flag is set to true.

While I understand why both does not work together by default, is there a way to do like on Excel where row selection is possible when clicking on the row index?

I've tried with the method setSelectedRows but it only works when row selection is enabled thus disabling cells selection.

I've also tried to change gridOptions dynamically when clicking on a specific column but nothing happend when I call render method.

Fab
  • 1
  • That is incorrect, it is documented at [Excel Copy Buffer Plugin- Wiki](https://github.com/ghiscoding/angular-slickgrid/wiki/Excel-Copy-Buffer-Plugin), also I didn't create this plugin and I actually never used it but you can see this SlickGrid [Example](http://6pac.github.io/SlickGrid/examples/example-excel-compatible-spreadsheet.html) for more demo and I suggest you look at its code. There are 2 SlickGrid Selection Models (cell selection, row selection) and the plugin only works with Cell Selection Model, it should throw an error otherwise (there's no bypass) – ghiscoding Jul 31 '23 at 13:42

1 Answers1

0

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();
    }
  }
}
Fab
  • 1