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

Replace gridList to grid #1565

Merged
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
4 changes: 1 addition & 3 deletions examples/simple/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import MUIDataTable from '../../src/';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormHelperText from '@material-ui/core/FormHelperText';
import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';

Expand All @@ -17,7 +15,7 @@ function Example() {
const [viewColumnBtn, setViewColumnBtn] = useState(true);
const [filterBtn, setFilterBtn] = useState(true);

const columns = ['Name', 'Title', 'Location'];
const columns = [{ name: 'Name', options: { filterOptions: { fullWidth: true } } }, 'Title', 'Location'];

const options = {
search: searchBtn,
Expand Down
57 changes: 36 additions & 21 deletions src/components/TableFilter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grid, GridList, GridListTile, TextField } from '@material-ui/core';
import { Grid, TextField } from '@material-ui/core';

import Button from '@material-ui/core/Button';
import Checkbox from '@material-ui/core/Checkbox';
Expand Down Expand Up @@ -165,7 +165,7 @@ class TableFilter extends React.Component {
column.filterOptions && column.filterOptions.renderValue ? column.filterOptions.renderValue : v => v;

return (
<GridListTile key={index} cols={2}>
<Grid item key={index} xs={6}>
<FormGroup>
<Grid item xs={12}>
<Typography variant="body2" className={classes.checkboxListTitle}>
Expand All @@ -187,7 +187,7 @@ class TableFilter extends React.Component {
color="primary"
className={classes.checkboxIcon}
onChange={this.handleCheckboxChange.bind(null, index, filterValue, column.name)}
checked={filterList[index].indexOf(filterValue) >= 0 ? true : false}
checked={filterList[index].indexOf(filterValue) >= 0}
classes={{
root: classes.checkbox,
checked: classes.checked,
Expand All @@ -201,7 +201,7 @@ class TableFilter extends React.Component {
))}
</Grid>
</FormGroup>
</GridListTile>
</Grid>
);
}

Expand All @@ -213,10 +213,14 @@ class TableFilter extends React.Component {
column.filterOptions && column.filterOptions.renderValue
? column.filterOptions.renderValue
: v => (v != null ? v.toString() : '');
const cols = (column.filterOptions && column.filterOptions.fullWidth) === true ? 2 : 1;
const width = (column.filterOptions && column.filterOptions.fullWidth) === true ? 12 : 6;

return (
<GridListTile key={index} cols={cols} classes={{ tile: classes.gridListTile }}>
<Grid
item
key={index}
xs={width}
classes={{ 'grid-xs-12': classes.gridListTile, 'grid-xs-6': classes.gridListTile }}>
<FormControl key={index} fullWidth>
<InputLabel htmlFor={column.name}>{column.label}</InputLabel>
<Select
Expand All @@ -235,7 +239,7 @@ class TableFilter extends React.Component {
))}
</Select>
</FormControl>
</GridListTile>
</Grid>
);
}

Expand All @@ -245,10 +249,14 @@ class TableFilter extends React.Component {
if (column.filterOptions && column.filterOptions.renderValue) {
console.warn('Custom renderValue not supported for textField filters');
}
const cols = (column.filterOptions && column.filterOptions.fullWidth) === true ? 2 : 1;
const width = (column.filterOptions && column.filterOptions.fullWidth) === true ? 12 : 6;

return (
<GridListTile key={index} cols={cols} classes={{ tile: classes.gridListTile }}>
<Grid
item
key={index}
xs={width}
classes={{ 'grid-xs-12': classes.gridListTile, 'grid-xs-6': classes.gridListTile }}>
<FormControl key={index} fullWidth>
<TextField
fullWidth
Expand All @@ -258,7 +266,7 @@ class TableFilter extends React.Component {
onChange={event => this.handleTextFieldChange(event, index, column.name)}
/>
</FormControl>
</GridListTile>
</Grid>
);
}

Expand All @@ -269,9 +277,13 @@ class TableFilter extends React.Component {
const { filterList } = this.state;
const renderItem =
column.filterOptions && column.filterOptions.renderValue ? column.filterOptions.renderValue : v => v;
const cols = (column.filterOptions && column.filterOptions.fullWidth) === true ? 2 : 1;
const width = (column.filterOptions && column.filterOptions.fullWidth) === true ? 12 : 6;
return (
<GridListTile key={index} cols={cols} classes={{ tile: classes.gridListTile }}>
<Grid
item
key={index}
xs={width}
classes={{ 'grid-xs-12': classes.gridListTile, 'grid-xs-6': classes.gridListTile }}>
<FormControl key={index} fullWidth>
<InputLabel htmlFor={column.name}>{column.label}</InputLabel>
<Select
Expand All @@ -287,7 +299,7 @@ class TableFilter extends React.Component {
<CheckboxComponent
data-description="table-filter"
color="primary"
checked={filterList[index].indexOf(filterValue) >= 0 ? true : false}
checked={filterList[index].indexOf(filterValue) >= 0}
value={filterValue != null ? filterValue.toString() : ''}
className={classes.checkboxIcon}
classes={{
Expand All @@ -300,14 +312,14 @@ class TableFilter extends React.Component {
))}
</Select>
</FormControl>
</GridListTile>
</Grid>
);
}

renderCustomField(column, index) {
const { classes, filterData, options } = this.props;
const { filterList } = this.state;
const cols = (column.filterOptions && column.filterOptions.fullWidth) === true ? 2 : 1;
const width = (column.filterOptions && column.filterOptions.fullWidth) === true ? 12 : 6;
const display =
(column.filterOptions && column.filterOptions.display) ||
(options.filterOptions && options.filterOptions.display);
Expand All @@ -321,11 +333,15 @@ class TableFilter extends React.Component {
}

return (
<GridListTile key={index} cols={cols} classes={{ tile: classes.gridListTile }}>
<Grid
item
key={index}
xs={width}
classes={{ 'grid-xs-12': classes.gridListTile, 'grid-xs-6': classes.gridListTile }}>
<FormControl key={index} fullWidth>
{display(filterList, this.handleCustomChange, index, column, filterData)}
</FormControl>
</GridListTile>
</Grid>
);
}

Expand Down Expand Up @@ -353,9 +369,8 @@ class TableFilter extends React.Component {
};

render() {
const { classes, columns, options, onFilterReset, customFooter, filterList, components = {} } = this.props;
const { classes, columns, options, customFooter, filterList, components = {} } = 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 @@ -380,7 +395,7 @@ class TableFilter extends React.Component {
</div>
<div className={classes.filtersSelected} />
</div>
<GridList cellHeight="auto" cols={filterGridColumns} spacing={34}>
<Grid container direction="row" justify="flex-start" alignItems="center" spacing={4}>
{columns.map((column, index) => {
if (column.filter) {
const filterType = column.filterType || options.filterType;
Expand All @@ -395,7 +410,7 @@ class TableFilter extends React.Component {
: this.renderSelect(column, index);
}
})}
</GridList>
</Grid>
{customFooter ? customFooter(filterList, this.applyFilters) : ''}
</div>
);
Expand Down