@azrico/reactgrid 1.6.11 → 1.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -37
- package/README.md +16 -0
- package/config/theme-extras.css +121 -120
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -0
- package/dist/src/func/func_colsizes.d.ts +22 -0
- package/dist/src/func/func_colsizes.js +86 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +16 -1
- package/dist/src/themes/azgrid-theme.css +121 -120
- package/dist/src/types/types.d.ts +7 -0
- package/dist/src/views/DataGrid.js +27 -2
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/func/func_colsizes.ts +74 -0
- package/src/index.tsx +1 -0
- package/src/themes/azgrid-theme.css +121 -120
- package/src/types/types.ts +170 -163
- package/src/views/DataGrid.tsx +405 -371
package/src/views/DataGrid.tsx
CHANGED
|
@@ -1,371 +1,405 @@
|
|
|
1
|
-
import '@inovua/reactdatagrid-enterprise/index.css';
|
|
2
|
-
import '../themes/base_styles.css';
|
|
3
|
-
import '../themes/grid.css';
|
|
4
|
-
import { get_default_key, get_row_id } from '../func/func_grid';
|
|
5
|
-
import { ContextMenu } from '@azrico/controls/context-menu';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
|
|
9
|
-
import clsx from 'clsx';
|
|
10
|
-
import { useComponentSize } from 'react-use-size';
|
|
11
|
-
|
|
12
|
-
import { AzGridOptions, AzGridProps, DataGridWrapperProps } from '../types/types';
|
|
13
|
-
import { useGridEvents } from '../hooks/useGridEvents';
|
|
14
|
-
import { useColumnData } from '../hooks/useColumnData';
|
|
15
|
-
import { useDataSource } from '../hooks/useDatasource';
|
|
16
|
-
import { useGridSearch } from '../hooks/useGridSearch';
|
|
17
|
-
import { apply_column_a11y } from '../func/func_a11y';
|
|
18
|
-
import {
|
|
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
|
-
const
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
];
|
|
50
|
-
//
|
|
51
|
-
const
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'
|
|
56
|
-
'
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
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
|
-
cached_columns,
|
|
103
|
-
props.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
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
|
-
const
|
|
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
|
-
|
|
1
|
+
import '@inovua/reactdatagrid-enterprise/index.css';
|
|
2
|
+
import '../themes/base_styles.css';
|
|
3
|
+
import '../themes/grid.css';
|
|
4
|
+
import { get_default_key, get_row_id } from '../func/func_grid';
|
|
5
|
+
import { ContextMenu } from '@azrico/controls/context-menu';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
import { useComponentSize } from 'react-use-size';
|
|
11
|
+
|
|
12
|
+
import { AzGridOptions, AzGridProps, DataGridWrapperProps } from '../types/types';
|
|
13
|
+
import { useGridEvents } from '../hooks/useGridEvents';
|
|
14
|
+
import { useColumnData } from '../hooks/useColumnData';
|
|
15
|
+
import { useDataSource } from '../hooks/useDatasource';
|
|
16
|
+
import { useGridSearch } from '../hooks/useGridSearch';
|
|
17
|
+
import { apply_column_a11y } from '../func/func_a11y';
|
|
18
|
+
import {
|
|
19
|
+
apply_column_sizes,
|
|
20
|
+
ColumnSizes,
|
|
21
|
+
isValidWidth,
|
|
22
|
+
loadColumnSizes,
|
|
23
|
+
saveColumnSizes,
|
|
24
|
+
} from '../func/func_colsizes';
|
|
25
|
+
import debounce from 'lodash.debounce';
|
|
26
|
+
import { id as rowIndexColumnId } from '@inovua/reactdatagrid-community/normalizeColumns/defaultRowIndexColumnId';
|
|
27
|
+
import { id as checkboxColumnId } from '@inovua/reactdatagrid-community/normalizeColumns/defaultCheckColumnId';
|
|
28
|
+
/* -------------------------------------------------------------------------- */
|
|
29
|
+
|
|
30
|
+
/* -------------------------------------------------------------------------- */
|
|
31
|
+
|
|
32
|
+
const defaultOptions: AzGridOptions = {
|
|
33
|
+
//filterTypes: defaultfilterTypes,
|
|
34
|
+
remoteFilter: false,
|
|
35
|
+
remoteSort: false,
|
|
36
|
+
editStartEvent: 'click',
|
|
37
|
+
rowReorderColumn: false,
|
|
38
|
+
resizable: true,
|
|
39
|
+
columnUserSelect: true,
|
|
40
|
+
rowIndexColumn: true,
|
|
41
|
+
rowHeight: 35,
|
|
42
|
+
};
|
|
43
|
+
const forcedOptions: AzGridOptions = {
|
|
44
|
+
idProperty: '__table_id',
|
|
45
|
+
nodesProperty: '__children',
|
|
46
|
+
theme: 'default-light',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const dynamic_option_names = ['selected', 'cellSelection', 'loading', 'limit', 'skip'];
|
|
50
|
+
// consumer callbacks forwarded to the grid; wrapped so a new function doesn't re-render the grid
|
|
51
|
+
const callback_option_names = [
|
|
52
|
+
'onSkipChange',
|
|
53
|
+
'onLimitChange',
|
|
54
|
+
'onEditComplete',
|
|
55
|
+
'onSelectionChange',
|
|
56
|
+
'onCellSelectionChange',
|
|
57
|
+
];
|
|
58
|
+
// props DataGridCore renders from, other props don't need to re-render the grid
|
|
59
|
+
const core_prop_names = [
|
|
60
|
+
'className',
|
|
61
|
+
'static_gridOptions',
|
|
62
|
+
'dynamic_gridOptions',
|
|
63
|
+
'columns',
|
|
64
|
+
'dataSource',
|
|
65
|
+
'gridRef',
|
|
66
|
+
'liveGridRef',
|
|
67
|
+
'allowChildRows',
|
|
68
|
+
'theme',
|
|
69
|
+
'dark',
|
|
70
|
+
'children',
|
|
71
|
+
];
|
|
72
|
+
/* -------------------------------------------------------------------------- */
|
|
73
|
+
export function AzGrid(props: AzGridProps) {
|
|
74
|
+
const gridRefBackup = React.useRef<any>(null);
|
|
75
|
+
const gridRef = props.gridRef || gridRefBackup;
|
|
76
|
+
const liveGridRef = React.useRef<any>(null);
|
|
77
|
+
const latestProps = React.useRef(props);
|
|
78
|
+
latestProps.current = props;
|
|
79
|
+
|
|
80
|
+
/* -------------------------------------------------------------------------- */
|
|
81
|
+
/* Columns */
|
|
82
|
+
/* -------------------------------------------------------------------------- */
|
|
83
|
+
const data_columns = useColumnData(props);
|
|
84
|
+
const dataSource = useDataSource(props.dataSource, props);
|
|
85
|
+
// saved widths are read once per grid id, resizing only updates this map so the columns aren't re-created mid-drag
|
|
86
|
+
const savedSizes = React.useRef<{ gridId?: string; sizes: ColumnSizes }>({ sizes: {} });
|
|
87
|
+
const saveSizesDebounced = React.useMemo(
|
|
88
|
+
() =>
|
|
89
|
+
props.gridId
|
|
90
|
+
? debounce(() => saveColumnSizes(props.gridId!, savedSizes.current.sizes), 300)
|
|
91
|
+
: null,
|
|
92
|
+
[props.gridId]
|
|
93
|
+
);
|
|
94
|
+
React.useEffect(() => () => saveSizesDebounced?.flush(), [saveSizesDebounced]);
|
|
95
|
+
const cached_columns = React.useMemo(() => {
|
|
96
|
+
if (!props.gridId) return data_columns;
|
|
97
|
+
if (savedSizes.current.gridId !== props.gridId)
|
|
98
|
+
savedSizes.current = { gridId: props.gridId, sizes: loadColumnSizes(props.gridId) };
|
|
99
|
+
return apply_column_sizes(data_columns, savedSizes.current.sizes);
|
|
100
|
+
}, [data_columns, props.gridId]);
|
|
101
|
+
const a11y_columns = React.useMemo(
|
|
102
|
+
() => cached_columns.map((col) => apply_column_a11y(col, { gridEditable: !!props.editable })),
|
|
103
|
+
[cached_columns, props.editable]
|
|
104
|
+
);
|
|
105
|
+
/* -------------------------------------------------------------------------- */
|
|
106
|
+
/* Row changes */
|
|
107
|
+
/* -------------------------------------------------------------------------- */
|
|
108
|
+
|
|
109
|
+
const base_gridOptions = React.useMemo<AzGridOptions>(() => {
|
|
110
|
+
const firstcolumn = cached_columns[0];
|
|
111
|
+
const licenseKey = props.licenseKey || get_default_key();
|
|
112
|
+
// call the latest consumer callback, only passed when the consumer gave one
|
|
113
|
+
const events: AzGridOptions = {};
|
|
114
|
+
callback_option_names.forEach((name) => {
|
|
115
|
+
if (props[name])
|
|
116
|
+
events[name] = (...args: any[]) => latestProps.current[name]?.(...args);
|
|
117
|
+
});
|
|
118
|
+
const extra_ops: AzGridOptions = {
|
|
119
|
+
licenseKey: licenseKey,
|
|
120
|
+
editable: props.editable as any, //bug in types of the plugin
|
|
121
|
+
treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
|
|
122
|
+
renderRowDetails: props.RowDetail,
|
|
123
|
+
};
|
|
124
|
+
return { ...defaultOptions, ...events, ...extra_ops };
|
|
125
|
+
}, [
|
|
126
|
+
cached_columns,
|
|
127
|
+
props.allowChildRows,
|
|
128
|
+
props.editable,
|
|
129
|
+
props.RowDetail,
|
|
130
|
+
props.licenseKey,
|
|
131
|
+
...callback_option_names.map((name) => !!props[name]),
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
const static_gridOptions = React.useMemo<AzGridOptions>(() => {
|
|
135
|
+
const finalres = { ...base_gridOptions, ...props.gridOptions, ...forcedOptions };
|
|
136
|
+
|
|
137
|
+
//append filter types instead of replacing it
|
|
138
|
+
if (finalres.filterTypes)
|
|
139
|
+
finalres.filterTypes = Object.assign(
|
|
140
|
+
{},
|
|
141
|
+
ReactDataGrid.defaultProps.filterTypes,
|
|
142
|
+
finalres.filterTypes
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (saveSizesDebounced)
|
|
146
|
+
finalres.onColumnResize = (info, ...rest) => {
|
|
147
|
+
const name = info.column.name ?? info.column.id;
|
|
148
|
+
if (name != null && isValidWidth(info.width)) {
|
|
149
|
+
savedSizes.current.sizes[name] = info.width;
|
|
150
|
+
saveSizesDebounced();
|
|
151
|
+
}
|
|
152
|
+
latestProps.current.gridOptions?.onColumnResize?.(info, ...rest);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return finalres;
|
|
156
|
+
}, [props.gridOptions, base_gridOptions, forcedOptions, saveSizesDebounced]);
|
|
157
|
+
|
|
158
|
+
const dynamic_gridOptions = React.useMemo<AzGridOptions>(
|
|
159
|
+
() => {
|
|
160
|
+
const res = {};
|
|
161
|
+
dynamic_option_names.map((r) => {
|
|
162
|
+
res[r] = props[r];
|
|
163
|
+
});
|
|
164
|
+
return res;
|
|
165
|
+
},
|
|
166
|
+
dynamic_option_names.map((r) => props[r])
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<DataGridEventsWrapper
|
|
171
|
+
{...props}
|
|
172
|
+
gridRef={gridRef}
|
|
173
|
+
liveGridRef={liveGridRef}
|
|
174
|
+
static_gridOptions={static_gridOptions}
|
|
175
|
+
dynamic_gridOptions={dynamic_gridOptions}
|
|
176
|
+
columns={a11y_columns}
|
|
177
|
+
dataSource={dataSource}
|
|
178
|
+
highlightedRow={props.highlightedRow}
|
|
179
|
+
/>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* -------------------------------------------------------------------------- */
|
|
184
|
+
/**
|
|
185
|
+
* Wrapper for menu events
|
|
186
|
+
* @param props
|
|
187
|
+
* @returns
|
|
188
|
+
*/
|
|
189
|
+
function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
190
|
+
const themeClass = `azgrid-theme-${props.theme ?? (props.dark ? 'dark' : 'light')}`;
|
|
191
|
+
/* -------------------------------------------------------------------------- */
|
|
192
|
+
const {
|
|
193
|
+
onRowClick,
|
|
194
|
+
onRowContextMenu,
|
|
195
|
+
onRenderRow,
|
|
196
|
+
onRenderLoadMask,
|
|
197
|
+
update_menuRow,
|
|
198
|
+
menuAnchorEl,
|
|
199
|
+
menuRow,
|
|
200
|
+
} = useGridEvents(props.gridRef.current, props);
|
|
201
|
+
const menuRowId =
|
|
202
|
+
menuAnchorEl && !props.hideContextMenu && props.contextMenuItems
|
|
203
|
+
? get_row_id(menuRow)
|
|
204
|
+
: undefined;
|
|
205
|
+
const consumerRowClassName = props.static_gridOptions?.rowClassName;
|
|
206
|
+
const rowClassName = React.useCallback(
|
|
207
|
+
(rowProps) => clsx(
|
|
208
|
+
typeof consumerRowClassName === 'function'
|
|
209
|
+
? consumerRowClassName(rowProps)
|
|
210
|
+
: consumerRowClassName,
|
|
211
|
+
menuRowId != null && get_row_id(rowProps.data) === menuRowId && 'azgrid-row--menu-open'
|
|
212
|
+
),
|
|
213
|
+
[consumerRowClassName, menuRowId]
|
|
214
|
+
);
|
|
215
|
+
/* -------------------------------------------------------------------------- */
|
|
216
|
+
/**
|
|
217
|
+
* Merge click events into grid options
|
|
218
|
+
*/
|
|
219
|
+
const static_gridOptions = React.useMemo<AzGridOptions>(() => {
|
|
220
|
+
const opts: any = props.static_gridOptions || {};
|
|
221
|
+
const events: AzGridOptions = {
|
|
222
|
+
onRowClick: onRowClick,
|
|
223
|
+
onRowContextMenu: onRowContextMenu,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// internal row attributes first, consumer's onRenderRow last so it can override them
|
|
227
|
+
const consumerOnRenderRow = opts.onRenderRow;
|
|
228
|
+
const renderProps: any = {
|
|
229
|
+
rowClassName,
|
|
230
|
+
onRenderRow: consumerOnRenderRow
|
|
231
|
+
? (rowProps) => {
|
|
232
|
+
onRenderRow(rowProps);
|
|
233
|
+
consumerOnRenderRow(rowProps);
|
|
234
|
+
}
|
|
235
|
+
: onRenderRow,
|
|
236
|
+
// track loading for aria-busy, the consumer's renderLoadMask (if any) still renders the mask
|
|
237
|
+
renderLoadMask: (maskProps) => {
|
|
238
|
+
onRenderLoadMask(maskProps);
|
|
239
|
+
return opts.renderLoadMask ? opts.renderLoadMask(maskProps) : undefined;
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const gridEditable = !!props.editable;
|
|
244
|
+
const a11yProps: any = {
|
|
245
|
+
headerProps: { role: 'row', 'aria-rowindex': 1, ...opts.headerProps },
|
|
246
|
+
rowIndexColumn: apply_column_a11y(
|
|
247
|
+
typeof opts.rowIndexColumn === 'object' ? opts.rowIndexColumn : {},
|
|
248
|
+
{ role: 'rowheader', gridEditable, id: rowIndexColumnId }
|
|
249
|
+
),
|
|
250
|
+
};
|
|
251
|
+
if (opts.checkboxColumn)
|
|
252
|
+
a11yProps.checkboxColumn = apply_column_a11y(
|
|
253
|
+
typeof opts.checkboxColumn === 'object' ? opts.checkboxColumn : {},
|
|
254
|
+
{ gridEditable, markReadonly: false, id: checkboxColumnId }
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
...opts,
|
|
259
|
+
...events,
|
|
260
|
+
...renderProps,
|
|
261
|
+
...a11yProps,
|
|
262
|
+
};
|
|
263
|
+
}, [
|
|
264
|
+
props.static_gridOptions,
|
|
265
|
+
props.editable,
|
|
266
|
+
onRowClick,
|
|
267
|
+
onRowContextMenu,
|
|
268
|
+
onRenderRow,
|
|
269
|
+
onRenderLoadMask,
|
|
270
|
+
rowClassName,
|
|
271
|
+
]);
|
|
272
|
+
|
|
273
|
+
/* -------------------------------------------------------------------------- */
|
|
274
|
+
// The menu is portaled to <body>, so it carries the theme class itself to get the theme tokens.
|
|
275
|
+
return (
|
|
276
|
+
<div className={clsx('azgrid-scope azgrid-flexed azgrid-flexlayout', themeClass)}>
|
|
277
|
+
{!props.hideContextMenu && props.contextMenuItems && (
|
|
278
|
+
<ContextMenu
|
|
279
|
+
classname={clsx('azgrid-context-menu', themeClass, props.contextMenuClassName)}
|
|
280
|
+
menuAnchorEl={menuAnchorEl}
|
|
281
|
+
menuRow={menuRow}
|
|
282
|
+
close={update_menuRow}
|
|
283
|
+
dontAutoClose={props.dontAutoCloseContextMenu ?? false}
|
|
284
|
+
escapeClosesContextMenu={props.escapeClosesContextMenu ?? false}
|
|
285
|
+
menu_items={props.contextMenuItems as any}
|
|
286
|
+
/>
|
|
287
|
+
)}
|
|
288
|
+
{props.details_dataSource ? (
|
|
289
|
+
<DataGridDetailsWrapper {...props} static_gridOptions={static_gridOptions} />
|
|
290
|
+
) : (
|
|
291
|
+
<DataGridSizeWrapper {...props} static_gridOptions={static_gridOptions} />
|
|
292
|
+
)}
|
|
293
|
+
</div>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function DataGridDetailsWrapper(props: DataGridWrapperProps) {
|
|
298
|
+
const cached_details_columns = useColumnData(props.details_columns);
|
|
299
|
+
const details_dataSource = useDataSource(props.details_dataSource, props);
|
|
300
|
+
const renderDetailsGrid = ({ data }) => {
|
|
301
|
+
return (
|
|
302
|
+
<ReactDataGrid
|
|
303
|
+
theme="default-light"
|
|
304
|
+
className={clsx('azgrid', `azgrid-theme-${props.theme ?? (props.dark ? 'dark' : 'light')}`)}
|
|
305
|
+
defaultFilterValue={props.details_filter}
|
|
306
|
+
dataSource={details_dataSource}
|
|
307
|
+
columns={cached_details_columns}
|
|
308
|
+
/>
|
|
309
|
+
);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Merge details into grid
|
|
314
|
+
*/
|
|
315
|
+
const static_gridOptions = React.useMemo<AzGridOptions>(() => {
|
|
316
|
+
const finalresult = props.static_gridOptions || {};
|
|
317
|
+
finalresult['renderDetailsGrid'] = renderDetailsGrid;
|
|
318
|
+
return finalresult;
|
|
319
|
+
}, [props.static_gridOptions, props.theme, props.dark]);
|
|
320
|
+
|
|
321
|
+
return <DataGridSizeWrapper {...props} static_gridOptions={static_gridOptions} />;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function DataGridSizeWrapper(props: DataGridWrapperProps) {
|
|
325
|
+
if (props.delayedSize) {
|
|
326
|
+
return <DataGridDelayedSizeWrapper {...props} />;
|
|
327
|
+
} else {
|
|
328
|
+
return <DataGridNormalSizeWrapper {...props} />;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* -------------------------------------------------------------------------- */
|
|
333
|
+
function DataGridNormalSizeWrapper(props: DataGridWrapperProps) {
|
|
334
|
+
return props.advancedFilterFields ? (
|
|
335
|
+
<DataGridSearchWrapper {...props} />
|
|
336
|
+
) : (
|
|
337
|
+
<DataGridCore {...props} />
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
function DataGridDelayedSizeWrapper(props: DataGridWrapperProps) {
|
|
341
|
+
const { ref, height, width } = useComponentSize();
|
|
342
|
+
return (
|
|
343
|
+
<div ref={ref} className={'azgrid-filler azgrid-nooverflow '}>
|
|
344
|
+
<div
|
|
345
|
+
className={'azgrid-delayedresize azgrid-flexlayout'}
|
|
346
|
+
style={{ height: height, width: width }}
|
|
347
|
+
>
|
|
348
|
+
{props.advancedFilterFields ? (
|
|
349
|
+
<DataGridSearchWrapper {...props} />
|
|
350
|
+
) : (
|
|
351
|
+
<DataGridCore {...props} />
|
|
352
|
+
)}
|
|
353
|
+
</div>
|
|
354
|
+
</div>
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
function DataGridSearchWrapper(props: DataGridWrapperProps) {
|
|
358
|
+
const { element, filteredData } = useGridSearch(props);
|
|
359
|
+
|
|
360
|
+
return (
|
|
361
|
+
<div className={'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'}>
|
|
362
|
+
{element}
|
|
363
|
+
<DataGridCore {...props} dataSource={filteredData} />
|
|
364
|
+
</div>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const DataGridCore = React.memo(DataGridCoreView, (prev, next) =>
|
|
368
|
+
core_prop_names.every((name) => prev[name] === next[name])
|
|
369
|
+
);
|
|
370
|
+
function DataGridCoreView(props: DataGridWrapperProps) {
|
|
371
|
+
const { gridRef, liveGridRef } = props;
|
|
372
|
+
const handle = React.useCallback(
|
|
373
|
+
(ref) => {
|
|
374
|
+
if (ref) gridRef.current = ref.current as any;
|
|
375
|
+
if (liveGridRef) liveGridRef.current = ref as any;
|
|
376
|
+
},
|
|
377
|
+
[gridRef, liveGridRef]
|
|
378
|
+
);
|
|
379
|
+
return (
|
|
380
|
+
<div className={clsx(props.className, 'azgrid-flexed', 'azgrid-flexlayout')}>
|
|
381
|
+
<ReactDataGrid
|
|
382
|
+
{...props.static_gridOptions}
|
|
383
|
+
{...props.dynamic_gridOptions}
|
|
384
|
+
rowIndexColumn={props.static_gridOptions.rowIndexColumn || true}
|
|
385
|
+
handle={handle}
|
|
386
|
+
theme="default-light"
|
|
387
|
+
className={clsx(
|
|
388
|
+
'azgrid azgrid-flexed',
|
|
389
|
+
props.allowChildRows && 'azgrid-tree',
|
|
390
|
+
`azgrid-theme-${props.theme ?? (props.dark ? 'dark' : 'light')}`
|
|
391
|
+
)}
|
|
392
|
+
columns={props.columns}
|
|
393
|
+
dataSource={props.dataSource}
|
|
394
|
+
/>
|
|
395
|
+
{props.children}
|
|
396
|
+
</div>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
/* -------------------------------------------------------------------------- */
|
|
400
|
+
/* -------------------------------------------------------------------------- */
|
|
401
|
+
/* -------------------------------------------------------------------------- */
|
|
402
|
+
/* -------------------------------------------------------------------------- */
|
|
403
|
+
|
|
404
|
+
/* -------------------------------------------------------------------------- */
|
|
405
|
+
export default AzGrid;
|