-
Notifications
You must be signed in to change notification settings - Fork 931
/
index.js
260 lines (250 loc) · 9.27 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import {
FormGroup,
FormLabel,
FormControl,
ListItemText,
TextField,
Checkbox,
FormControlLabel,
Grid,
Select,
InputLabel,
MenuItem
} from '@mui/material';
import React from 'react';
import MUIDataTable from '../../src';
class Example extends React.Component {
state = {
ageFilterChecked: false
};
render() {
const columns = [
{
name: 'Name',
options: {
filter: true,
filterOptions: {
renderValue: v => v ? v.replace(/^(\w).* (.*)$/, '$1. $2') : ''
},
//display: 'excluded',
filterType: 'dropdown'
},
},
{
label: 'Modified Title Label',
name: 'Title',
options: {
filter: true,
customFilterListOptions: {
render: v => v.toLowerCase()
},
},
},
{
label: 'Location',
name: 'Location',
options: {
filter: true,
display: 'true',
filterType: 'custom',
customFilterListOptions: {
render: v => v.map(l => l.toUpperCase()),
update: (filterList, filterPos, index) => {
console.log('update');
console.log(filterList, filterPos, index);
filterList[index].splice(filterPos, 1);
return filterList;
}
},
filterOptions: {
logic: (location, filters, row) => {
if (filters.length) return !filters.includes(location);
return false;
},
display: (filterList, onChange, index, column) => {
const optionValues = ['Minneapolis', 'New York', 'Seattle'];
return (
<FormControl>
<InputLabel htmlFor='select-multiple-chip'>
Location
</InputLabel>
<Select
multiple
value={filterList[index]}
renderValue={selected => selected.join(', ')}
onChange={event => {
filterList[index] = event.target.value;
onChange(filterList[index], index, column);
}}
>
{optionValues.map(item => (
<MenuItem key={item} value={item}>
<Checkbox
color='primary'
checked={filterList[index].indexOf(item) > -1}
/>
<ListItemText primary={item} />
</MenuItem>
))}
</Select>
</FormControl>
);
}
}
}
},
{
name: 'Age',
options: {
filter: true,
filterType: 'custom',
// if the below value is set, these values will be used every time the table is rendered.
// it's best to let the table internally manage the filterList
//filterList: [25, 50],
customFilterListOptions: {
render: v => {
if (v[0] && v[1] && this.state.ageFilterChecked) {
return [`Min Age: ${v[0]}`, `Max Age: ${v[1]}`];
} else if (v[0] && v[1] && !this.state.ageFilterChecked) {
return `Min Age: ${v[0]}, Max Age: ${v[1]}`;
} else if (v[0]) {
return `Min Age: ${v[0]}`;
} else if (v[1]) {
return `Max Age: ${v[1]}`;
}
return [];
},
update: (filterList, filterPos, index) => {
console.log('customFilterListOnDelete: ', filterList, filterPos, index);
if (filterPos === 0) {
filterList[index].splice(filterPos, 1, '');
} else if (filterPos === 1) {
filterList[index].splice(filterPos, 1);
} else if (filterPos === -1) {
filterList[index] = [];
}
return filterList;
},
},
filterOptions: {
names: [],
logic(age, filters) {
if (filters[0] && filters[1]) {
return age < filters[0] || age > filters[1];
} else if (filters[0]) {
return age < filters[0];
} else if (filters[1]) {
return age > filters[1];
}
return false;
},
display: (filterList, onChange, index, column) => (
<div>
<FormLabel>Age</FormLabel>
<FormGroup row>
<TextField
label='min'
value={filterList[index][0] || ''}
onChange={event => {
filterList[index][0] = event.target.value;
onChange(filterList[index], index, column);
}}
style={{ width: '45%', marginRight: '5%' }}
/>
<TextField
label='max'
value={filterList[index][1] || ''}
onChange={event => {
filterList[index][1] = event.target.value;
onChange(filterList[index], index, column);
}}
style={{ width: '45%' }}
/>
<FormControlLabel
control={
<Checkbox
checked={this.state.ageFilterChecked}
onChange={event => this.setState({ ageFilterChecked: event.target.checked })}
/>
}
label='Separate Values'
style={{ marginLeft: '0px' }}
/>
</FormGroup>
</div>
),
},
print: false,
},
},
{
name: 'Salary',
options: {
filter: true,
filterType: 'checkbox',
filterOptions: {
names: ['Lower wages', 'Average wages', 'Higher wages'],
logic(salary, filterVal) {
salary = salary.replace(/[^\d]/g, '');
const show =
(filterVal.indexOf('Lower wages') >= 0 && salary < 100000) ||
(filterVal.indexOf('Average wages') >= 0 && salary >= 100000 && salary < 200000) ||
(filterVal.indexOf('Higher wages') >= 0 && salary >= 200000);
return !show;
},
},
sort: false,
},
},
];
const data = [
['Gabby George', 'Business Analyst', 'Minneapolis', 30, '$100,000'],
['Aiden Lloyd', 'Business Consultant', 'Dallas', 55, '$200,000'],
['Jaden Collins', 'Attorney', 'Santa Ana', 27, '$500,000'],
['Franky Rees', 'Business Analyst', 'St. Petersburg', 22, '$50,000'],
['Aaren Rose', 'Business Consultant', 'Toledo', 28, '$75,000'],
['Blake Duncan', 'Business Management Analyst', 'San Diego', 65, '$94,000'],
['Frankie Parry', 'Agency Legal Counsel', 'Jacksonville', 71, '$210,000'],
['Lane Wilson', 'Commercial Specialist', 'Omaha', 19, '$65,000'],
['Robin Duncan', 'Business Analyst', 'Los Angeles', 20, '$77,000'],
['Mel Brooks', 'Business Consultant', 'Oklahoma City', 37, '$135,000'],
['Harper White', 'Attorney', 'Pittsburgh', 52, '$420,000'],
['Kris Humphrey', 'Agency Legal Counsel', 'Laredo', 30, '$150,000'],
['Frankie Long', 'Industrial Analyst', 'Austin', 31, '$170,000'],
['Brynn Robbins', 'Business Analyst', 'Norfolk', 22, '$90,000'],
['Justice Mann', 'Business Consultant', 'Chicago', 24, '$133,000'],
['Addison Navarro', 'Business Management Analyst', 'New York', 50, '$295,000'],
['Jesse Welch', 'Agency Legal Counsel', 'Seattle', 28, '$200,000'],
['Eli Mejia', 'Commercial Specialist', 'Long Beach', 65, '$400,000'],
['Gene Leblanc', 'Industrial Analyst', 'Hartford', 34, '$110,000'],
['Danny Leon', 'Computer Scientist', 'Newark', 60, '$220,000'],
['Lane Lee', 'Corporate Counselor', 'Cincinnati', 52, '$180,000'],
['Jesse Hall', 'Business Analyst', 'Baltimore', 44, '$99,000'],
['Danni Hudson', 'Agency Legal Counsel', 'Tampa', 37, '$90,000'],
['Terry Macdonald', 'Commercial Specialist', 'Miami', 39, '$140,000'],
['Justice Mccarthy', 'Attorney', 'Tucson', 26, '$330,000'],
['Silver Carey', 'Computer Scientist', 'Memphis', 47, '$250,000'],
['Franky Miles', 'Industrial Analyst', 'Buffalo', 49, '$190,000'],
['Glen Nixon', 'Corporate Counselor', 'Arlington', 44, '$80,000'],
['Gabby Strickland', 'Business Process Consultant', 'Scottsdale', 26, '$45,000'],
['Mason Ray', 'Computer Scientist', 'San Francisco', 39, '$142,000'],
];
const options = {
filter: true,
filterType: 'multiselect',
responsive: 'standard',
setFilterChipProps: (colIndex, colName, data) => {
//console.log(colIndex, colName, data);
return {
color: 'primary',
variant: 'outlined',
className: 'testClass123',
};
}
};
return (
<MUIDataTable title={'ACME Employee list - customizeFilter'} data={data} columns={columns} options={options} />
);
}
}
export default Example;