Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Grid & DataView Events

Ghislain B edited this page Nov 3, 2017 · 41 revisions

SlickGrid has nice amount of Grid Events or DataView Events which you can use by simply hooking a subscribe to them (the subscribe is a custom SlickGrid Event and is not an Observable type function similarly). To get access to all these events, you will have to bind to the Grid and the DataView objects which are exposed in Angular-Slickgrid with EventEmitter (Angular-Slickgrid uses emit after the Grid and DataView becomes ready). Once these are called, it basically mean that the Grid and DataView are ready and we can subscribe to any of the SlickGrid Events.

View

Bind (dataviewChanged) and (gridChanged)

<angular-slickgrid 
  gridId="grid2" 
  (dataviewChanged)="dataviewReady($event)" 
  (gridChanged)="gridReady($event)"
  [columnDefinitions]="columnDefinitions" 
  [gridOptions]="gridOptions" 
  [dataset]="dataset">
</angular-slickgrid>

Component

Once the Grid and DataView are ready, you can subscribe to any SlickGrid Events (click to see the full list). See below for the gridReady(grid) and dataviewReady(dataview) functions.

  • The GridExtraUtils is to bring easy access to common functionality like getting a column from it's row and cell index.
  • The example shown below is subscribing to onClick and ask the user to confirm a delete, then will delete it from the DataView.
import { Component, Input, OnInit } from '@angular/core';
import { Editors, Formatters, GridExtraUtils } from 'angular-slickgrid';

@Component({
  templateUrl: './grid-editor.component.html'
})
export class GridEditorComponent implements OnInit {
  columnDefinitions: Column[];
  gridOptions: GridOption;
  dataset: any[];  
  dataviewObj: any;

  constructor() {}

  ngOnInit(): void {
    this.columnDefinitions = [
      { id: 'delete', field: 'id', formatter: Formatters.deleteIcon, maxWidth: 30 }
      // ...
    ];

    this.gridOptions = {
      editable: true,
      enableCellNavigation: true,
      autoEdit: true
    };
  }

  gridReady(grid) {
    grid.onCellChange.subscribe((e, args) => {
      console.log('onCellChange', args);
      // for example, CRUD with WebAPI calls
    });
    grid.onClick.subscribe((e, args) => {
      const column = GridExtraUtils.getColumnDefinitionAndData(args);

      if (column.columnDef.id === 'delete') {
        if (confirm('Are you sure?')) {
          this.dataviewObj.deleteItem(column.dataContext.id);
          this.dataviewObj.refresh();
        }
      }
    });

  }
  dataviewReady(dataview) {
    this.dataviewObj = dataview;
  }
}

Contents

Clone this wiki locally