Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single grid column for single filter #613

Merged
merged 1 commit into from
May 23, 2019
Merged
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/components/TableFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class TableFilter extends React.Component {
render() {
const { classes, columns, options, onFilterReset } = this.props;
const textLabels = options.textLabels.filter;
const filterGridColumns = columns.filter(col => col.filter).length === 1 ? 1 : 2;

return (
<div className={classes.root}>
Expand All @@ -294,7 +295,7 @@ class TableFilter extends React.Component {
</div>
<div className={classes.filtersSelected} />
</div>
<GridList cellHeight="auto" cols={2}>
<GridList cellHeight="auto" cols={filterGridColumns}>
{columns.map((column, index) => {
if (column.filter) {
const filterType = column.filterType || options.filterType;
Expand Down
5 changes: 1 addition & 4 deletions src/components/TableFilterList.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class TableFilterList extends React.Component {
filterListRenderers: PropTypes.array.isRequired,
/** Columns used to describe table */
columnNames: PropTypes.PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.string,
PropTypes.shape({ name: PropTypes.string.isRequired }),
]),
PropTypes.oneOfType([PropTypes.string, PropTypes.shape({ name: PropTypes.string.isRequired })]),
).isRequired,
/** Callback to trigger filter update */
onFilterUpdate: PropTypes.func,
Expand Down
16 changes: 13 additions & 3 deletions test/MUIDataTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,12 @@ describe('<MUIDataTable />', function() {
const columnNames = columns.map(column => ({ name: column.name }));

const mountWrapper = mount(
<TableFilterList filterList={filterList} filterListRenderers={filterListRenderers} filterUpdate={() => true} columnNames={columnNames} />,
<TableFilterList
filterList={filterList}
filterListRenderers={filterListRenderers}
filterUpdate={() => true}
columnNames={columnNames}
/>,
);
const actualResult = mountWrapper.find(Chip);
assert.strictEqual(actualResult.length, 1);
Expand All @@ -432,7 +437,12 @@ describe('<MUIDataTable />', function() {
const columnNames = columns.map(column => ({ name: column.name }));

const mountWrapper = mount(
<TableFilterList filterList={filterList} filterListRenderers={filterListRenderers} filterUpdate={() => true} columnNames={columnNames} />,
<TableFilterList
filterList={filterList}
filterListRenderers={filterListRenderers}
filterUpdate={() => true}
columnNames={columnNames}
/>,
);
const actualResult = mountWrapper.find(Chip);
assert.strictEqual(actualResult.length, 1);
Expand Down Expand Up @@ -477,7 +487,7 @@ describe('<MUIDataTable />', function() {
it('should have the proper column name in onFilterChange when applying filters', () => {
let changedColumn;
const options = {
onFilterChange: column => changedColumn = column
onFilterChange: column => (changedColumn = column),
};

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
Expand Down