Skip to content

Commit 54b564d

Browse files
author
Fabian Kretzer
authored
Merge pull request #391 from eddyson-de/more-than-one-filter-bug
More than one filter bug
2 parents f165e73 + c329194 commit 54b564d

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

lib/FilterHandler.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ const withFilterHandler = ComponentToWrap => {
8080

8181
updateFilterConfig(filterFunction, filterComponent, columnName){
8282
if (columnName !== undefined){
83-
let newState = {};
84-
if (filterFunction !== undefined){
85-
newState.filterFunctions = Object.assign({}, this.state.filterFunctions);
86-
newState.filterFunctions[columnName] = filterFunction;
87-
}
88-
if (filterComponent !== undefined){
89-
newState.filterComponents = Object.assign({}, this.state.filterComponents);
90-
newState.filterComponents[columnName] = filterComponent;
91-
}
92-
this.setState(newState);
83+
this.setState((prevState) => {
84+
let newState = {};
85+
if (filterFunction !== undefined){
86+
newState.filterFunctions = Object.assign({}, prevState.filterFunctions);
87+
newState.filterFunctions[columnName] = filterFunction;
88+
}
89+
if (filterComponent !== undefined){
90+
newState.filterComponents = Object.assign({}, prevState.filterComponents);
91+
newState.filterComponents[columnName] = filterComponent;
92+
}
93+
return newState;
94+
});
9395

9496
} else {
9597
let newState = {};

test/FilterTests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,18 @@ describe('Grid filter tests', function () {
341341
);
342342
expect(grid.find("th input").at(0).prop("type")).be.equal("checkbox");
343343
});
344+
345+
it('Should use more than one custom filterFunction', ()=>{
346+
let grid = mount(
347+
<Grid objects={[{name: "a", age: 1}, {name: "b", age: 2}]} defaultFilter={[{columnName: "name", expression: "a"}]} >
348+
<Column name="name" >
349+
<Cell content={()=> <div>FOO</div>}/>
350+
<Filter match={() => false}/>
351+
</Column>
352+
<Column name="age" >
353+
<Cell content={()=> <div>BAR</div>}/>
354+
<Filter match={() => false}/>
355+
</Column>
356+
</Grid>);
357+
});
344358
});

0 commit comments

Comments
 (0)