Skip to content

Commit

Permalink
Merge pull request #13 from lowdefy/fix-update-versions
Browse files Browse the repository at this point in the history
Do not call onRowSelected on selected and unselected
  • Loading branch information
Gervwyk authored Apr 7, 2022
2 parents 5da65c9 + b03f17b commit 5ab39fd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,37 @@ 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.

##### Input Blocks

- `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.
Expand Down
15 changes: 9 additions & 6 deletions src/AgGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand All @@ -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,
});
}
Expand All @@ -97,7 +101,6 @@ class AgGrid extends React.Component {
name: 'onFilterChanged',
event: { rows: event.api.rowModel.rowsToDisplay.map((row) => row.data) },
});
console.log(event);
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/AgGridInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AgGridInput extends React.Component {
row: event.data,
selected: this.gridApi.getSelectedRows(),
rowIndex: event.rowIndex,
index: parseInt(event.node.id),
},
});
}
Expand All @@ -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,
});
}
Expand Down Expand Up @@ -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,
},
});
}
Expand Down

0 comments on commit 5ab39fd

Please sign in to comment.