1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import * as React from 'react';
import { ColumnModel, ColumnType } from './columnModel';
import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
import TableCell from '@material-ui/core/TableCell';
import TableRow from '@material-ui/core/TableRow';
import Input from '@material-ui/core/Input';
const styles = (theme: Theme) => createStyles({
container: {
display: 'flex',
flexWrap: 'wrap',
},
input: {
margin: theme.spacing.unit,
},
});
interface IEnhancedTableFilterComponentProps extends WithStyles<typeof styles> {
onFilterChanged: (property: string, filterTerm: string) => void;
filter: { [property: string]: string };
columns: ColumnModel<{}>[];
enableSelection?: boolean;
}
class EnhancedTableFilterComponent extends React.Component<IEnhancedTableFilterComponentProps> {
createFilterHandler = (property: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.onFilterChanged && this.props.onFilterChanged(property, event.target.value);
};
render() {
const { columns, filter, classes } = this.props;
return (
<TableRow>
{ this.props.enableSelection
? <TableCell padding="checkbox" style={ { width: "50px" } }>
</TableCell>
: null
}
{ columns.map(col => {
const style = col.width ? { width: col.width } : {};
return (
<TableCell
key={ col.property }
padding={ col.disablePadding ? 'none' : 'default' }
style={ style }
>
{ col.disableFilter || (col.type === ColumnType.custom) ? null : <Input
className={ classes.input }
inputProps={ {
'aria-label': 'Filter',
} }
value={ filter[col.property] || '' }
onChange={ this.createFilterHandler(col.property) }
/> }
</TableCell>
);
}, this) }
</TableRow>
);
}
}
export const EnhancedTableFilter = withStyles(styles)(EnhancedTableFilterComponent);
|