Skip to content

Commit

Permalink
Merge pull request #10 from lowdefy/events-filter-change
Browse files Browse the repository at this point in the history
feat: Add onFilterChanged event.
  • Loading branch information
Gervwyk authored Apr 7, 2022
2 parents 4cbc69b + c51117c commit e5ed4dd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The block types are hosted at:
- `selected: object[]`: List of selected row objects.
- `rowIndex: number`: List index of the clicked row.
- `colId: string`: Column id of the clicked cell.
- `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`:
- `row: object`: Row data object.
- `selected: object[]`: List of selected row objects.
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
},
{
"name": "Johann Möller",
"url": "https://github.com/JohannMoller"
}
],
"repository": {
Expand Down
12 changes: 12 additions & 0 deletions src/AgGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AgGrid extends React.Component {
this.onCellClicked = this.onCellClicked.bind(this);
this.onRowSelected = this.onRowSelected.bind(this);
this.onSelectionChanged = this.onSelectionChanged.bind(this);
this.onFilterChanged = this.onFilterChanged.bind(this);
}

onGridReady(params) {
Expand Down Expand Up @@ -83,13 +84,24 @@ class AgGrid extends React.Component {
}
}

onFilterChanged(event) {
if (this.props.events.onFilterChanged) {
this.props.methods.triggerEvent({
name: 'onFilterChanged',
event: { rows: event.api.rowModel.rowsToDisplay.map((row) => row.data) },
});
console.log(event);
}
}

render() {
const { quickFilterValue, ...someProperties } = this.props.properties;
if (quickFilterValue && quickFilterValue === '') {
this.gridApi.setQuickFilter(quickFilterValue); // check if empty string matches all
}
return (
<AgGridReact
onFilterChanged={this.onFilterChanged}
onSelectionChanged={this.onSelectionChanged}
onRowSelected={this.onRowSelected}
onRowClicked={this.onRowClick}
Expand Down
10 changes: 10 additions & 0 deletions src/AgGridInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AgGridInput extends React.Component {
this.onSelectionChanged = this.onSelectionChanged.bind(this);
this.onRowDragEnd = this.onRowDragEnd.bind(this);
this.onCellValueChanged = this.onCellValueChanged.bind(this);
this.onFilterChanged = this.onFilterChanged.bind(this);
}

onGridReady(params) {
Expand Down Expand Up @@ -88,6 +89,15 @@ class AgGridInput extends React.Component {
}
}

onFilterChanged(event) {
if (this.props.events.onFilterChanged) {
this.props.methods.triggerEvent({
name: 'onFilterChanged',
event: { rows: event.api.rowModel.rowsToDisplay.map((row) => row.data) },
});
}
}

onRowDragEnd(event) {
if (event.overNode !== event.node) {
const fromData = event.node.data;
Expand Down

0 comments on commit e5ed4dd

Please sign in to comment.