SlickGrid has a nice amount of events, see the full list of Available Events, which you can use by simply hook a subscribe to them (the subscribe are a custom SlickGrid Event). There are 2 options to get access to all these events (For the first 2 you will have to get access to the Grid and the DataView objects which are exposed in Aurelia-Slickgrid):
From the list below, the number 1. is by far the easiest and preferred way
with delegate Event Dispatch binding so you can add event handlers in your view. This library bubbles all events for the Grid and DataView by converting the camelcase methods to kebab case (ie. onMouseEnter will be on-mouse-enter. Slickgrid's EventData and Args parameters will be passed via $event.detail.eventData and $event.detail.args
with bindable values, so you can just call gridChanged and/or dataviewChanged
1. Example with delegate Event Dispatch (asgOnX)
Event Dispatch is the preferred way to access any of the Available Events
All the Slick Grid events (and DataView) are exposed through Event Dispatch and are available as (sgOnX)and that's it.
Once the Grid and DataView are ready, see all Available Events. See below for the gridChanged(grid) and dataviewChanged(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.
Technically, the Grid and DataView are created at the same time by Aurelia-Slickgrid, so it's ok to call the dataViewObj within some code of the gridObjChanged() function since DataView object will already be available at that time.
Note The example below is demonstrated with bind with event Changed hook on the grid and dataview objects. However you can also use the EventAggregator as shown earlier. It's really up to you to choose the way you want to call these objects.
ViewModel
import { inject, bindable } from'aurelia-framework';import { Editors, Formatters, GridExtraUtils } from'aurelia-slickgrid';exportclassGridEditorComponent { @bindable() gridObj:any; @bindable() dataviewObj:any; columnDefinitions:Column[]; gridOptions:GridOption; dataset:any[]; dataviewObj:any; onCellChangeSubscriber:any; onCellClickSubscriber:any;constructor(private controlService:ControlAndPluginService) {// define the grid options & columns and then create the grid itselfthis.defineGrid(); }detached() {// don't forget to unsubscribe to the Slick Grid Eventsthis.onCellChangeSubscriber.unsubscribe();this.onCellClickSubscriber.unsubscribe(); }defineGrid() {this.columnDefinitions = [ { id:'delete', field:'id', formatter:Formatters.deleteIcon, maxWidth:30 }// ... ];this.gridOptions = { editable:true, enableCellNavigation:true, autoEdit:true }; }// with bindable Dataview and Changed eventdataviewObjChanged(dataview) {this.dataviewObj = dataview; }// with bindable Grid and Changed eventgridObjChanged(grid) {this.gridObj = grid;this.subscribeToSomeGridEvents(grid); }subscribeToSomeGridEvents(grid) {this.onCellChangeSubscriber =grid.onCellChange.subscribe((e, args) => {console.log('onCellChange', args);// for example, CRUD with WebAPI calls });this.onCellClickSubscriber =grid.onClick.subscribe((e, args) => {constcolumn=GridExtraUtils.getColumnDefinitionAndData(args);if (column.columnDef.id ==='delete') {if (confirm('Are you sure?')) {this.dataviewObj.deleteItem(column.dataContext.id);this.dataviewObj.refresh(); } } }); }}