Skip to content

Commit 3f47395

Browse files
authored
Merge pull request mbrn#1281 from re-anderson/feature/call-onFilterChange
call onFilterChange
2 parents b6bc545 + 994d57f commit 3f47395

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/material-table.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,19 @@ export default class MaterialTable extends React.Component {
447447

448448
this.onQueryChange(query);
449449
}
450-
else {
451-
this.setState(this.dataManager.getRenderState());
450+
else {
451+
this.setState(this.dataManager.getRenderState(), () => {
452+
if(this.props.onFilterChange) {
453+
const appliedFilters = this.state.columns
454+
.filter(a => a.tableData.filterValue)
455+
.map(a => ({
456+
column: a,
457+
operator: "=",
458+
value: a.tableData.filterValue
459+
}));
460+
this.props.onFilterChange(appliedFilters);
461+
}
462+
});
452463
}
453464
}, this.props.options.debounceInterval)
454465

src/prop-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export const propTypes = {
166166
}),
167167
initialFormData: PropTypes.object,
168168
onSearchChange: PropTypes.func,
169+
onFilterChange: PropTypes.func,
169170
onColumnDragged: PropTypes.func,
170171
onGroupRemoved: PropTypes.func,
171172
onSelectionChange: PropTypes.func,

types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export interface MaterialTableProps<RowData extends object> {
3030
onRowClick?: (event?: React.MouseEvent, rowData?: RowData, toggleDetailPanel?: (panelIndex?: number) => void) => void;
3131
onRowSelected?: (rowData: RowData) => void;
3232
onSearchChange?: (searchText: string) => void;
33+
/** An event fired when the table has finished filtering data
34+
* @param {Filter<RowData>[]} filters All the filters that are applied to the table
35+
*/
36+
onFilterChange?: (filters: Filter<RowData>[]) => void;
3337
onSelectionChange?: (data: RowData[], rowData?: RowData) => void;
3438
onTreeExpandChange?: (data: any, isExpanded: boolean) => void;
3539
onQueryChange?: (query: Query<RowData>) => void;

0 commit comments

Comments
 (0)