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';
10 import { Select, FormControl, InputLabel, MenuItem } from '@material-ui/core';
13 const styles = (theme: Theme) => createStyles({
19 margin: theme.spacing.unit,
23 interface IEnhancedTableFilterComponentProps extends WithStyles<typeof styles> {
24 onFilterChanged: (property: string, filterTerm: string) => void;
25 filter: { [property: string]: string };
26 columns: ColumnModel<{}>[];
27 enableSelection?: boolean;
30 class EnhancedTableFilterComponent extends React.Component<IEnhancedTableFilterComponentProps> {
31 createFilterHandler = (property: string) => (event: React.ChangeEvent<HTMLInputElement|HTMLSelectElement|HTMLTextAreaElement>) => {
32 this.props.onFilterChanged && this.props.onFilterChanged(property, event.target.value);
36 const { columns, filter, classes } = this.props;
39 { this.props.enableSelection
40 ? <TableCell padding="checkbox" style={ { width: "50px" } }>
44 { columns.map(col => {
45 const style = col.width ? { width: col.width } : {};
49 padding={ col.disablePadding ? 'none' : 'default' }
52 { col.disableFilter || (col.type === ColumnType.custom)
54 : (col.type === ColumnType.boolean)
55 ? <Select className={classes.input} value={filter[col.property] !== undefined ? filter[col.property] : ''} onChange={this.createFilterHandler(col.property)} inputProps={{ name: `${col.property}-bool`, id: `${col.property}-bool` }} >
56 <MenuItem value={undefined}>
59 <MenuItem value={true as any as string}>{ col.labels ? col.labels["true"]:"true"}</MenuItem>
60 <MenuItem value={false as any as string}>{ col.labels ? col.labels["false"] : "false"}</MenuItem>
62 : <Input className={classes.input} inputProps={{ 'aria-label': 'Filter' }} value={filter[col.property] || ''} onChange={this.createFilterHandler(col.property)} />}
71 export const EnhancedTableFilter = withStyles(styles)(EnhancedTableFilterComponent);