-
Notifications
You must be signed in to change notification settings - Fork 0
/
PopularFeaturesDemo.tsx
419 lines (405 loc) · 11.5 KB
/
PopularFeaturesDemo.tsx
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
import * as React from 'react';
import {
DataGridPremium,
DataGridPremiumProps,
gridClasses,
GridColDef,
GridEventListener,
GridRenderCellParams,
GridRowParams,
GridToolbarContainer,
GridToolbarQuickFilter,
GridValueFormatterParams,
useGridApiRef,
} from '@mui/x-data-grid-premium';
import Link from '@mui/material/Link';
import Chip from '@mui/material/Chip';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import ArrowUp from '@mui/icons-material/KeyboardArrowUp';
import ArrowDown from '@mui/icons-material/KeyboardArrowDown';
import { useTheme } from '@mui/material/styles';
import AggregationRowGrouping from '../aggregation/AggregationRowGrouping';
import BasicColumnPinning from '../column-pinning/BasicColumnPinning';
import ColumnSelectorGrid from '../column-visibility/ColumnSelectorGrid';
import ExcelExport from '../export/ExcelExport';
import QuickFilteringGrid from '../filtering/QuickFilteringGrid';
import BasicDetailPanels from '../master-detail/BasicDetailPanels';
import RowGroupingInitialState from '../row-grouping/RowGroupingInitialState';
import RowOrderingGrid from '../row-ordering/RowOrderingGrid';
import RowPinningWithPagination from '../row-pinning/RowPinningWithPagination';
import RestoreStateInitialState from '../state/RestoreStateInitialState';
import TreeDataFullExample from '../tree-data/TreeDataFullExample';
import ColumnVirtualizationGrid from '../virtualization/ColumnVirtualizationGrid';
import FullFeaturedDemo from './FullFeaturedDemo';
import LazyLoadingGrid from '../row-updates/LazyLoadingGrid';
import BasicGroupingDemo from '../column-groups/BasicGroupingDemo';
import EditingWithDatePickers from '../recipes-editing/EditingWithDatePickers';
type Row = {
id: number;
name: string;
description: string;
plan: string;
detailPage: string;
demo: JSX.Element;
newBadge?: boolean;
};
export const featuresSet: Row[] = [
{
id: 1,
name: 'Master detail',
description: 'A parent row with a collapsible child panel',
plan: 'Pro',
detailPage: '/master-detail/',
demo: <BasicDetailPanels />,
},
{
id: 2,
name: 'Inline editing',
description:
'Edit your data inside the cells by double-clicking or pressing Enter',
plan: 'Community',
detailPage: '/editing/',
demo: <EditingWithDatePickers />,
},
{
id: 3,
name: 'Column groups',
description: 'Group columns in a multi-level hierarchy',
plan: 'Community',
detailPage: '/column-groups/',
newBadge: true,
demo: <BasicGroupingDemo />,
},
{
id: 4,
name: 'Lazy Loading',
description: 'Easily paginate your rows and only fetch what you need',
plan: 'Pro',
detailPage: '/pagination/',
newBadge: true,
demo: <LazyLoadingGrid />,
},
{
id: 5,
name: 'Save and restore state',
description:
'Save and restore internal state and configurations like active filters and sorting',
plan: 'Community',
detailPage: '/state/#save-and-restore-the-state',
demo: <RestoreStateInitialState />,
},
{
id: 6,
name: 'Row Grouping',
description: 'Group rows with repeating column values',
plan: 'Premium',
detailPage: '/row-grouping/',
demo: <RowGroupingInitialState />,
},
{
id: 7,
name: 'Excel export',
description:
'Easily export the rows in various file formats such as CSV, PDF or Excel',
plan: 'Premium',
detailPage: '/export/#excel-export',
demo: <ExcelExport />,
},
{
id: 8,
name: 'Quick filter',
description: 'Use a single text input to filter multiple fields',
plan: 'Community',
detailPage: '/filtering/#quick-filter',
demo: <QuickFilteringGrid />,
},
{
id: 9,
name: 'Row reorder',
description: 'Drag and drop to reorder your data',
plan: 'Pro',
detailPage: '/row-ordering/',
demo: <RowOrderingGrid />,
},
{
id: 10,
name: 'Column Pinning',
description: 'Pin your columns to the left or right',
plan: 'Pro',
detailPage: '/column-pinning/',
demo: <BasicColumnPinning />,
},
{
id: 11,
name: 'Row Pinning',
description: 'Pin your rows up or down',
plan: 'Pro',
detailPage: '/row-pinning/',
demo: <RowPinningWithPagination />,
newBadge: true,
},
{
id: 12,
name: 'Aggretation and Summary rows',
description: 'Set summary footer rows or inline summaries with row grouping',
plan: 'Premium',
detailPage: '/aggregation/',
demo: <AggregationRowGrouping />,
newBadge: true,
},
{
id: 13,
name: 'Column Visibility',
description:
'Display different columns in different use cases by defining which columns are visible',
plan: 'Community',
detailPage: '/column-visibility/',
demo: <ColumnSelectorGrid />,
},
{
id: 14,
name: 'Column Virtualization',
description: 'High performance support for thousands of columns',
plan: 'Community',
detailPage: '/virtualization/#column-virtualization',
demo: <ColumnVirtualizationGrid />,
},
{
id: 15,
name: 'Row Virtualization',
description: 'High performance support for vast volume of data',
plan: 'Pro',
detailPage: '/virtualization/#row-virtualization',
demo: <FullFeaturedDemo />,
},
{
id: 16,
name: 'Tree data',
description: 'Support rows with parent / child relationship',
plan: 'Pro',
detailPage: '/tree-data/',
demo: <TreeDataFullExample />,
},
];
const getChipProperties = (plan: string) => {
switch (plan.toLowerCase()) {
case 'premium':
return { avatarLink: '/static/x/premium.svg', color: '#ffecc8' };
case 'pro':
return { avatarLink: '/static/x/pro.svg', color: '#c8e9ff' };
default:
return { avatarLink: undefined, color: '#c8ffdb' };
}
};
const PlanTag = (props: { plan: string }) => {
const chipPropperties = getChipProperties(props.plan);
const avatar = !chipPropperties.avatarLink ? undefined : (
<Avatar src={chipPropperties.avatarLink} />
);
return (
<Chip
avatar={avatar}
sx={{ background: chipPropperties.color, color: 'rgba(0, 0, 0, 0.87)' }}
label={props.plan}
/>
);
};
const CustomToolbar = () => {
return (
<GridToolbarContainer sx={{ p: 1 }}>
<GridToolbarQuickFilter />
</GridToolbarContainer>
);
};
const RowDemo = (props: { row: Row }) => {
const { row } = props;
const theme = useTheme();
const gridBgColor = theme.palette.mode === 'dark' ? '#000' : '#fff';
const panelColor = theme.palette.mode === 'dark' ? 'transparent' : '#efefef';
return (
<Box sx={{ py: 2, background: panelColor }}>
<Box style={{ width: '90%', margin: 'auto', background: gridBgColor }}>
{row.demo}
</Box>
</Box>
);
};
const columns: GridColDef[] = [
{
field: 'name',
headerName: 'Feature name',
maxWidth: 160,
flex: 0.2,
minWidth: 100,
groupable: false,
renderCell: (params) => {
if (!params.value) {
return '';
}
return (
<Box
sx={{
width: '100%',
height: '100%',
position: 'relative',
display: 'flex',
alignItems: 'center',
}}
>
<Typography sx={{ fontSize: '1rem', fontWeight: '500' }}>
<Link
href={`/x/react-data-grid${params.row.detailPage}`}
target="_blank"
>
{params.value}
</Link>
</Typography>
{params.row.newBadge && (
<Box
sx={{
width: 'fit-content',
height: 'fit-content',
fontSize: '0.8em',
fontWeight: 600,
position: 'absolute',
textAlign: 'center',
top: -13,
left: -20,
background: '#fcf0a0',
color: '#af5b00',
px: 1,
borderRadius: 10,
}}
>
New
</Box>
)}
</Box>
);
},
},
{
field: 'description',
headerName: 'Brief description',
groupable: false,
flex: 0.5,
minWidth: 120,
},
{
field: 'plan',
headerName: 'Plan',
maxWidth: 130,
flex: 0.3,
type: 'singleSelect',
valueOptions: ['Premium', 'Pro', 'Community'],
renderCell: (params: GridRenderCellParams<string>) => {
if (!params.value) {
return '';
}
return <PlanTag plan={params.value} />;
},
sortComparator: (p1, p2) => {
function getSortingValue(plan: string) {
switch (plan) {
case 'Pro':
return 1;
case 'Premium':
return 2;
default:
return 0;
}
}
const p1Value = getSortingValue(p1);
const p2Value = getSortingValue(p2);
return p1Value - p2Value;
},
},
];
export default function PopularFeaturesDemo() {
const apiRef = useGridApiRef();
const getDetailPanelContent = React.useCallback<
NonNullable<DataGridPremiumProps['getDetailPanelContent']>
>((params: GridRowParams) => {
return <RowDemo row={params.row} />;
}, []);
const getRowHeight = React.useCallback<
NonNullable<DataGridPremiumProps['getRowHeight']>
>(() => 'auto', []);
const getDetailPanelHeight = React.useCallback<
NonNullable<DataGridPremiumProps['getDetailPanelHeight']>
>(() => 'auto', []);
const onRowClick = React.useCallback<GridEventListener<'rowClick'>>(
(params) => {
const rowNode = apiRef.current.getRowNode(params.id);
if (rowNode && rowNode.isAutoGenerated) {
apiRef.current.setRowChildrenExpansion(params.id, !rowNode.childrenExpanded);
} else {
apiRef.current.toggleDetailPanel(params.id);
}
},
[apiRef],
);
const memoizedGroupingDef = React.useMemo(() => {
return {
headerName: 'Grouped by Plan',
width: 200,
valueFormatter: (params: GridValueFormatterParams) => {
if (!params.value) {
return '';
}
return <PlanTag plan={params.value} />;
},
};
}, []);
return (
<div style={{ height: 'fit-content', width: '100%' }}>
<DataGridPremium
apiRef={apiRef}
autoHeight
disableSelectionOnClick
onRowClick={onRowClick}
components={{
Toolbar: CustomToolbar,
DetailPanelExpandIcon: ArrowDown,
DetailPanelCollapseIcon: ArrowUp,
}}
componentsProps={{
toolbar: { showQuickFilter: true, quickFilterProps: { debounceMs: 500 } },
}}
getDetailPanelContent={getDetailPanelContent}
getDetailPanelHeight={getDetailPanelHeight}
getRowHeight={getRowHeight}
initialState={{
sorting: {
sortModel: [{ field: 'plan', sort: 'asc' }],
},
}}
sx={{
[`& .${gridClasses.cell}`]: {
py: 2,
},
[`& .${gridClasses.columnHeaderTitle}`]: {
fontWeight: 400,
},
[`& .${gridClasses.detailPanel}`]: {
background: 'transparent',
},
[`& .${gridClasses.cell}:focus, & .${gridClasses.cell}:focus-within`]: {
outline: 'none',
},
[`& .${gridClasses.columnHeader}:focus, & .${gridClasses.columnHeader}:focus-within`]:
{
outline: 'none',
},
border: 0,
}}
rows={featuresSet}
columns={columns}
hideFooter
groupingColDef={memoizedGroupingDef}
/>
</div>
);
}