diff --git a/README.md b/README.md index a1bdbd2..b48e0c3 100644 --- a/README.md +++ b/README.md @@ -31,21 +31,24 @@ The block types are hosted at: ##### All Blocks - `onCellClick`: Trigger event when a cell is clicked and pass the following to `_event`: - - `row: object`: Row data object. - `cell: object`: Cell data object. - - `selected: object[]`: List of selected row objects. - - `rowIndex: number`: List index of the clicked row. - `colId: string`: Column id of the clicked cell. + - `index: number`: Data index of the clicked row as per provided data array. + - `row: object`: Row data object. + - `rowIndex: number`: List index of the clicked row, changes with data sorting or filtering. + - `selected: object[]`: List of selected row objects. - `onFilterChanged`: Trigger event when the filter changes and pass the following to `_event`: - `rows: object[]`: List of row objects matched by the filter. - `onRowClick`: Trigger event when a row is clicked and pass the following to `_event`: + - `index: number`: Data index of the clicked row as per provided data array. - `row: object`: Row data object. + - `rowIndex: number`: List index of the clicked row, changes with data sorting or filtering. - `selected: object[]`: List of selected row objects. - - `rowIndex: number`: List index of the clicked row. - `onRowSelected`: Trigger event when a row is selected and pass the following to `_event`: + - `index: number`: Data index of the clicked row as per provided data array. - `row: object`: Row data object. + - `rowIndex: number`: List index of the clicked row, changes with data sorting or filtering. - `selected: object[]`: List of selected row objects. - - `rowIndex: number`: List index of the clicked row. - `onSelectionChanged`: Triggered when the selected rows is changed and pass the following to `_event`: - `selected: object[]`: List of selected row objects. @@ -53,11 +56,12 @@ The block types are hosted at: - `onCellValueChanged`: Triggered when a cell value is changed on the grid. The following is passed to the action `_event`: - `field: string`: The field name of the changed cell. + - `index: number`: Data index of the clicked row as per provided data array. - `newRowData: object[]`: The table data with the change applied. - `newValue: any`: The updated cell value. - `oldValue: any`: The cell value before the update was made. - `rowData: object`: The row data after the cell value has been changed. - - `rowIndex: number`: Array index of the row for the changed cell. + - `rowIndex: number`: List index of the clicked row, changes with data sorting or filtering. - `onRowDragEnd`: Triggered when a row is dragged to another position in the grid. The following is passed to the action `_event`: - `fromData: object`: Row data of the row selection which to moved. - `fromIndex: number`: Array index of the row selection which to moved. diff --git a/src/AgGrid.js b/src/AgGrid.js index a8451ae..161dbb3 100644 --- a/src/AgGrid.js +++ b/src/AgGrid.js @@ -50,8 +50,9 @@ class AgGrid extends React.Component { onRowClick(event) { if (this.props.events.onRowClick) { this.props.methods.triggerEvent({ - name: 'onRowClick', event: { row: event.data, selected: this.gridApi.getSelectedRows() }, + index: parseInt(event.node.id), + name: 'onRowClick', rowIndex: event.rowIndex, }); } @@ -62,21 +63,24 @@ class AgGrid extends React.Component { this.props.methods.triggerEvent({ name: 'onCellClick', event: { - row: event.data, cell: { column: event.colDef.field, value: event.value }, - selected: this.gridApi.getSelectedRows(), - rowIndex: event.rowIndex, colId: event.column.colId, + index: parseInt(event.node.id), + row: event.data, + rowIndex: event.rowIndex, + selected: this.gridApi.getSelectedRows(), }, }); } } onRowSelected(event) { + if (!event.node.selected) return; // see https://stackoverflow.com/a/63265775/2453657 if (this.props.events.onRowSelected) { this.props.methods.triggerEvent({ - name: 'onRowSelected', event: { row: event.data, selected: this.gridApi.getSelectedRows() }, + index: parseInt(event.node.id), + name: 'onRowSelected', rowIndex: event.rowIndex, }); } @@ -97,7 +101,6 @@ class AgGrid extends React.Component { name: 'onFilterChanged', event: { rows: event.api.rowModel.rowsToDisplay.map((row) => row.data) }, }); - console.log(event); } } diff --git a/src/AgGridInput.js b/src/AgGridInput.js index dc9306a..cadb795 100644 --- a/src/AgGridInput.js +++ b/src/AgGridInput.js @@ -57,6 +57,7 @@ class AgGridInput extends React.Component { row: event.data, selected: this.gridApi.getSelectedRows(), rowIndex: event.rowIndex, + index: parseInt(event.node.id), }, }); } @@ -67,21 +68,24 @@ class AgGridInput extends React.Component { this.props.methods.triggerEvent({ name: 'onCellClick', event: { - row: event.data, cell: { column: event.colDef.field, value: event.value }, - selected: this.gridApi.getSelectedRows(), - rowIndex: event.rowIndex, colId: event.column.colId, + index: parseInt(event.node.id), + row: event.data, + rowIndex: event.rowIndex, + selected: this.gridApi.getSelectedRows(), }, }); } } onRowSelected(event) { + if (!event.node.selected) return; // see https://stackoverflow.com/a/63265775/2453657 if (this.props.events.onRowSelected) { this.props.methods.triggerEvent({ - name: 'onRowSelected', event: { row: event.data, selected: this.gridApi.getSelectedRows() }, + index: parseInt(event.node.id), + name: 'onRowSelected', rowIndex: event.rowIndex, }); } @@ -138,12 +142,13 @@ class AgGridInput extends React.Component { this.props.methods.triggerEvent({ name: 'onCellValueChanged', event: { - rowIndex: parseInt(params.node.id), - rowData: params.data, field: params.colDef.field, + index: parseInt(params.node.id), + newRowData, newValue: params.newValue, oldValue: params.oldValue, - newRowData, + rowData: params.data, + rowIndex: params.rowIndex, }, }); }