Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Adding the ability to use complex forms in filters #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build/reactable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,11 @@ window.ReactDOM["default"] = window.ReactDOM;
}
} else {
// Apply custom filter
if (this._filterable[filterColumn]((0, _libExtract_data_from.extractDataFrom)(data, filterColumn).toString(), filter)) {
var rawData = (0, _libExtract_data_from.extractDataFrom)(data, filterColumn);
if (rawData.toString() !== '[object Object]') {
rawData = rawData.toString();
}
if (this._filterable[filterColumn](rawData, filter)) {
matchedChildren.push(children[i]);
break;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/reactable/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ var Table = (function (_React$Component) {
}
} else {
// Apply custom filter
if (this._filterable[filterColumn]((0, _libExtract_data_from.extractDataFrom)(data, filterColumn).toString(), filter)) {
var rawData = (0, _libExtract_data_from.extractDataFrom)(data, filterColumn);
if (rawData.toString() !== '[object Object]') {
rawData = rawData.toString();
}
if (this._filterable[filterColumn](rawData, filter)) {
matchedChildren.push(children[i]);
break;
}
Expand Down
6 changes: 5 additions & 1 deletion src/reactable/table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ export class Table extends React.Component {
}
} else {
// Apply custom filter
if (this._filterable[filterColumn](extractDataFrom(data, filterColumn).toString(), filter)) {
let rawData = extractDataFrom(data, filterColumn);
if (rawData.toString() !== '[object Object]') {
rawData = rawData.toString();
}
if (this._filterable[filterColumn](rawData, filter)) {
matchedChildren.push(children[i]);
break;
}
Expand Down
54 changes: 54 additions & 0 deletions tests/reactable_test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,60 @@ describe('Reactable', function() {
});
});
});


context('with custom filter and complex contents', function() {
before(function() {
this.component = ReactDOM.render(
<Reactable.Table className="table" id="table"
filterable={[
{
column: 'State',
filterFunction: function(contents, filter) {
return (
typeof(contents) !== 'undefined' && typeof(filter) !== 'undefined' &&
contents.props.value.toLowerCase().indexOf(filter) > -1
);
},
}
]}
filterPlaceholder="Filter Results"
columns={['State', 'Description', 'Tag']}>
<Reactable.Tr>
<Reactable.Td column='State'><div value="NY">New York</div></Reactable.Td>
<Reactable.Td column='Description'>this is some text</Reactable.Td>
<Reactable.Td column='Tag'>new</Reactable.Td>
</Reactable.Tr>
<Reactable.Tr>
<Reactable.Td column='State'><div value="NM">New Mexico</div></Reactable.Td>
<Reactable.Td column='Description'>lorem ipsum</Reactable.Td>
<Reactable.Td column='Tag'>old x</Reactable.Td>
</Reactable.Tr>
<Reactable.Tr>
<Reactable.Td column='State'><div value="CO">Colorado</div></Reactable.Td>
<Reactable.Td column='Description'>lol</Reactable.Td>
<Reactable.Td column='Tag'>renewed x</Reactable.Td>
</Reactable.Tr>
<Reactable.Tr>
<Reactable.Td column='State'><div value="AK">Alaska</div></Reactable.Td>
<Reactable.Td column='Description'>bacon</Reactable.Td>
<Reactable.Td column='Tag'>new</Reactable.Td>
</Reactable.Tr>
</Reactable.Table>,
ReactableTestUtils.testNode()
);

this.component.filterBy('AK');
});

after(ReactableTestUtils.resetTestEnvironment);

it('filters based on a prop specified in the custom filter', function() {
ReactableTestUtils.expectRowText(0, ['Alaska', 'bacon', 'new']);
});
});


});

describe('directly passing a data array with non-string data', function() {
Expand Down