Skip to content

Commit

Permalink
correctly filter boolean values (fixes #170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenberger committed Nov 16, 2016
1 parent 8ed412c commit 02a03ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/Ardagryd.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ const defaultConfig = {
filterFunction: ({displayValue, expression}) => {
if (!(typeof expression === 'string') || expression === '' || expression === undefined || expression === null){return true;}
if (displayValue === undefined || displayValue === null) {return false;}
if ((typeof displayValue === 'string' ) && displayValue.toLowerCase().indexOf(expression.toLowerCase()) === -1){
const valueType = typeof displayValue;
if ((valueType === 'string' ) && displayValue.toLowerCase().indexOf(expression.toLowerCase()) === -1){
return false;
} else if ((typeof displayValue === 'object') || (typeof displayValue === 'number') ){
} else if (['number', 'boolean', 'object'].indexOf(valueType) !== -1){
return JSON.stringify(displayValue).toLowerCase().indexOf(expression.toLowerCase()) !== -1;
}
else return true;
Expand Down
10 changes: 9 additions & 1 deletion test/FilterTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,22 @@ describe('Grid filter tests', function () {
expect(grid.find("tbody").children().length).be.equal(1);
});

it('Filter should filte numerical values', ()=>{
it('Filter should filter numerical values', ()=>{
let grid = mount(<Grid objects={[{name: "aa", age: 2}, {name: "ab", age: 57}, {name: "ccb", age: 7}]} />);
expect(grid.find("tbody").children().length).be.equal(3);

grid.setProps({filter: [{columnName: "age", expression: "7"}]});

expect(grid.find("tbody").children().length).be.equal(2);
});

it('Filter should filter boolean values', ()=>{
let grid = mount(<Grid objects={[{name: "aa", x: false}, {name: "ab", x: true}, {name: "ccb", x: true}]} />);
expect(grid.find("tbody").children().length).be.equal(3);

grid.setProps({filter: [{columnName: "x", expression: "true"}]});
expect(grid.find("tbody").children().length).be.equal(2);
});

it('Should use displayValueGetter for default filter function', () => {
let grid = mount(<Grid objects={[{name: "Foo"}]}
Expand Down

0 comments on commit 02a03ca

Please sign in to comment.