-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathindex.js
139 lines (128 loc) · 3.87 KB
/
index.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from "react";
import MUIDataTable from "../../src/";
import Chip from '@mui/material/Chip';
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
import TableFilterList from '../../src/components/TableFilterList';
import MuiTooltip from '@mui/material/Tooltip';
import Fade from "@mui/material/Fade";
import Checkbox from '@mui/material/Checkbox';
import Radio from '@mui/material/Radio';
import TableViewCol from './TableViewCol';
const CustomChip = (props) => {
const { label, onDelete, columnNames, className, index } = props;
return (<Chip
className={className}
variant="outlined"
color={columnNames[index].name === 'Company' ? 'secondary' : 'primary'}
label={label}
onDelete={onDelete}
/>);
};
const CustomTooltip = (props) => {
return (
<MuiTooltip
title={props.title}
interactive={true}
TransitionComponent={Fade}
TransitionProps={{ timeout: 250 }}
leaveDelay={250}>{props.children}</MuiTooltip>
);
};
const CustomCheckbox = (props) => {
let newProps = Object.assign({}, props);
newProps.color = props['data-description'] === 'row-select' ? 'secondary' : 'primary';
if (props['data-description'] === 'row-select') {
return (<Radio {...newProps} />);
} else {
return (<Checkbox {...newProps} />);
}
};
const CustomFilterList = (props) => {
return <TableFilterList {...props} ItemComponent={CustomChip} />;
};
class Example extends React.Component {
render() {
const columns = [
{ name: 'Name' },
{
name: 'Company',
options: {
filter: true,
filterType: 'custom',
filterList: ['Test Corp'],
customFilterListOptions: {
render: v => {
if (v.length !== 0) {
return `Company: ${v[0]}`;
}
return false;
},
update: (filterList) => filterList,
},
filterOptions: {
names: [],
logic(status, filter) {
if (filter.length > 0) {
return status !== filter[0];
}
return false;
},
display: (filterList, onChange, index, column) => (
<Select
onChange={event => {
filterList[index][0] = event.target.value;
onChange(filterList[index], index, column);
}}
value={filterList[index]}
>
<MenuItem value="Test Corp">{'Test Corp'}</MenuItem>
<MenuItem value="Other Corp">{'Other Corp'}</MenuItem>
</Select>
)
},
},
},
{ name: 'City', label: 'City Label', options: { filterList: ['Dallas'] } },
{ name: 'State' },
{
name: 'Empty',
options: {
empty: true,
filterType: 'checkbox',
filterOptions: {
renderValue: (val) => (val ? val : '(Empty)')
}
}
},
];
const data = [
['Joe James', 'Test Corp', 'Yonkers', 'NY'],
['John Walsh', 'Test Corp', 'Hartford', null],
['Bob Herm', 'Other Corp', 'Tampa', 'FL'],
['James Houston', 'Test Corp', 'Dallas', 'TX'],
];
let options = {
onFilterChipClose: (index, removedFilter, filterList) => {
console.log(index, removedFilter, filterList);
},
selectableRows: 'single',
selectToolbarPlacement: 'none',
};
return (
<MUIDataTable
title={"ACME Employee list"}
data={data}
columns={columns}
options={options}
components={{
TableFilterList: CustomFilterList,
Tooltip: CustomTooltip,
Checkbox: CustomCheckbox,
TableViewCol: TableViewCol
}}
/>
);
}
}
export default Example;