2 import * as React from 'react';
3 import { ColumnModel, ColumnType } from './columnModel';
4 import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
7 import TableCell from '@material-ui/core/TableCell';
8 import TableRow from '@material-ui/core/TableRow';
9 import Input from '@material-ui/core/Input';
12 const styles = (theme: Theme) => createStyles({
18 margin: theme.spacing.unit,
22 interface IEnhancedTableFilterComponentProps extends WithStyles<typeof styles> {
23 onFilterChanged: (property: string, filterTerm: string) => void;
24 filter: { [property: string]: string };
25 columns: ColumnModel<{}>[];
26 enableSelection?: boolean;
29 class EnhancedTableFilterComponent extends React.Component<IEnhancedTableFilterComponentProps> {
30 createFilterHandler = (property: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
31 this.props.onFilterChanged && this.props.onFilterChanged(property, event.target.value);
35 const { columns, filter, classes } = this.props;
38 { this.props.enableSelection
39 ? <TableCell padding="checkbox" style={ { width: "50px" } }>
43 { columns.map(col => {
44 const style = col.width ? { width: col.width } : {};
48 padding={ col.disablePadding ? 'none' : 'default' }
51 { col.disableFilter || (col.type === ColumnType.custom) ? null : <Input
52 className={ classes.input }
54 'aria-label': 'Filter',
56 value={ filter[col.property] || '' }
57 onChange={ this.createFilterHandler(col.property) }
67 export const EnhancedTableFilter = withStyles(styles)(EnhancedTableFilterComponent);