-
-
Couldn't load subscription status.
- Fork 118
Grid & DataView Events
SlickGrid has a nice amount of Grid Events or DataView Events which you can use by simply hooking a subscribe to them (please note, subscribe are custom SlickGrid Event and are NOT RxJS Observables, however they are very similar concept). 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.
All the Slick Grid events (and DataView) are exposed through Event Dispatch and are available as (sg-on-X), for example
<angular-slickgrid gridId="grid2"
(onAngularGridCreated)="angularGridReady($event)"
(sg-on-cell-change)="onCellChanged($event.detail.eventData, $event.detail.args)"
(sg-on-click)="onCellClicked($event.detail.eventData, $event.detail.args)"
[columnDefinitions]="columnDefinitions" [gridOptions]="gridOptions" [dataset]="dataset">
</angular-slickgrid>Hook yourself to the Changed event of the bindable grid object.
export class GridEditorComponent {
onCellChanged(e, args) {
this.updatedObject = args.item;
this.angularGrid.resizerService.resizeGrid(10);
}
}Angular-Slickgrid have the following Event Emitters that you can hook to. However please note that onDataviewCreated
and onGridCreated are less used now that onAngularGridCreated exposes both the Slick Grid & DataView object.
onAngularGridCreatedonDataviewCreatedonGridCreatedonBeforeGridCreateonBeforeGridDestroyonAfterGridDestroyed
Bind (onDataviewCreated) and (onGridCreated) if you want to call any SlickGrid legacy functions.
<angular-slickgrid
gridId="grid2"
(onDataviewCreated)="dataviewReady($event)"
(onGridCreated)="gridReady($event)"
[columnDefinitions]="columnDefinitions"
[gridOptions]="gridOptions"
[dataset]="dataset">
</angular-slickgrid>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
GridExtraUtilsis to bring easy access to common functionality like getting acolumnfrom it'srowandcellindex. - The example shown below is subscribing to
onClickand ask the user to confirm a delete, then will delete it from theDataView. - Technically, the
GridandDataVieware created at the same time byAngular-Slickgrid, so it's ok to call thedataViewObjwithin some code of thegridReady()function sinceDataViewobject will already be available at that time.
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
- Angular-Slickgrid Wiki
- Installation
- Styling
- Interfaces/Models
- Testing Patterns
- Column Functionalities
- Global Grid Options
- Localization
- Events
- Grid Functionalities
- Auto-Resize / Resizer Service
- Resize by Cell Content
- Composite Editor
- Context Menu
- Custom Tooltip
- Add/Delete/Update or Highlight item
- Dynamically Change Row CSS Classes
- Excel Copy Buffer
- Export to Excel
- Export to File (CSV/Txt)
- Grid State & Presets
- Grouping & Aggregators
- Row Detail
- SlickGrid Controls
- SlickGrid Plugins
- Pinning (frozen) of Columns/Rows
- Tree Data Grid
- SlickGrid & DataView objects
- Addons (controls/plugins)
- Backend Services