简体   繁体   中英

Angular Slickgrid | How to Enable/Disable checkbox dynamically (Not show/hide checkbox)

export class Example1 implements OnInit {
  prepareGrid() {
    this.gridOptions = {
      enableRowSelection: true,
      enableCheckboxSelector: true,
      checkboxSelector: {
        // you can override the logic for showing (or not) the expand icon
        // for example, display the expand icon only on every 2nd row
        selectableOverride: (row: number, dataContext: any, grid: any) => (dataContext.id % 2 === 1)
      },
      multiSelect: false,
      rowSelectionOptions: {
        // True (Single Selection), False (Multiple Selections)
        selectActiveRow: true,
      },
    };
  }
}

We can use enableCheckboxSelector to show/hide checkbox. But how to enable/disable checkbox based on some condition dynamically?

The question is already answered in the Wiki documentations, you can use selectableOverride , refer to Row Selection - Wiki , but it seems that you already have that code, or maybe you didn't understand what that was for?

If you want to change the selected row(s) at any point in time, then simply use the built-in SlickGrid method setSelectedRows(rowIndexes) which requires an array of row indexes, passing an empty array will clear all selections.

<angular-slickgrid 
  gridId="grid4" 
  [columnDefinitions]="columnDefinitions" 
  [gridOptions]="gridOptions"
  [dataset]="dataset" 
  (onAngularGridCreated)="angularGridReady($event)"> <!-- <<== you need this line !-->
</angular-slickgrid>
angularGridReady(angularGrid: AngularGridInstance) {
  this.angularGrid = angularGrid;
}

changeRowSelection() {
  angularGrid.slickGrid.setSelectedRows(rowIndexes);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM