@azrico/reactgrid 1.2.5 → 1.2.7
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 +27 -0
- package/dist/src/example.js +27 -8
- package/dist/src/func/{helpers.js → func_child.js} +11 -7
- package/dist/src/func/func_grid.d.ts +38 -0
- package/dist/src/func/func_grid.js +276 -0
- package/dist/src/index.js +0 -3
- package/dist/src/views/DataGrid.d.ts +5 -13
- package/dist/src/views/DataGrid.js +66 -285
- package/package.json +1 -1
- package/src/example.tsx +27 -8
- package/src/func/{helpers.ts → func_child.ts} +18 -10
- package/src/func/func_grid.ts +288 -0
- package/src/index.tsx +3 -3
- package/src/views/DataGrid.tsx +92 -300
- /package/dist/src/func/{helpers.d.ts → func_child.d.ts} +0 -0
|
@@ -5,40 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.AzGrid = AzGrid;
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
exports.get_col_header = get_col_header;
|
|
9
|
-
exports.get_col_name = get_col_name;
|
|
10
8
|
require("@inovua/reactdatagrid-enterprise/index.css");
|
|
11
9
|
require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
|
|
12
10
|
require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
|
|
13
11
|
require("../themes/base_styles.css");
|
|
14
12
|
require("../themes/grid.css");
|
|
13
|
+
var _func_grid = require("../func/func_grid");
|
|
15
14
|
var _controls = require("@azrico/controls");
|
|
16
15
|
var _react = _interopRequireDefault(require("react"));
|
|
17
|
-
var
|
|
18
|
-
var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
|
|
19
|
-
var _NumericEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/NumericEditor"));
|
|
16
|
+
var _func_child = require("../func/func_child");
|
|
20
17
|
var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
|
|
21
|
-
var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
|
|
22
18
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
23
|
-
var _object = require("@azrico/object");
|
|
24
19
|
var _reactUseSize = require("react-use-size");
|
|
25
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
21
|
/* -------------------------------------------------------------------------- */
|
|
27
|
-
// const defaultfilterTypes: FilterTypes = {
|
|
28
|
-
// string: {
|
|
29
|
-
// type: 'string',
|
|
30
|
-
// emptyValue: '',
|
|
31
|
-
// operators: [
|
|
32
|
-
// {
|
|
33
|
-
// name: 'contains',
|
|
34
|
-
// fn: ({ value, filterValue, data }) => {
|
|
35
|
-
// console.log('fn');
|
|
36
|
-
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
37
|
-
// },
|
|
38
|
-
// },
|
|
39
|
-
// ],
|
|
40
|
-
// },
|
|
41
|
-
// };
|
|
42
22
|
const defaultOptions = {
|
|
43
23
|
//filterTypes: defaultfilterTypes,
|
|
44
24
|
remoteFilter: false,
|
|
@@ -56,11 +36,6 @@ const forcedOptions = {
|
|
|
56
36
|
idProperty: '__table_id',
|
|
57
37
|
nodesProperty: '__children'
|
|
58
38
|
};
|
|
59
|
-
const defaultColumnOptions = {
|
|
60
|
-
draggable: false,
|
|
61
|
-
lockable: false,
|
|
62
|
-
editable: false
|
|
63
|
-
};
|
|
64
39
|
const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
|
|
65
40
|
/* -------------------------------------------------------------------------- */
|
|
66
41
|
function AzGrid(props) {
|
|
@@ -70,7 +45,7 @@ function AzGrid(props) {
|
|
|
70
45
|
/* Columns */
|
|
71
46
|
/* -------------------------------------------------------------------------- */
|
|
72
47
|
const cached_columns = _react.default.useMemo(() => {
|
|
73
|
-
return ApplyColumnData(props);
|
|
48
|
+
return (0, _func_grid.ApplyColumnData)(props);
|
|
74
49
|
}, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
|
|
75
50
|
/* -------------------------------------------------------------------------- */
|
|
76
51
|
/* Row changes */
|
|
@@ -78,46 +53,16 @@ function AzGrid(props) {
|
|
|
78
53
|
const cached_data = _react.default.useRef();
|
|
79
54
|
const last_cache_info = _react.default.useRef();
|
|
80
55
|
const dataSource = _react.default.useCallback(async dt => {
|
|
81
|
-
|
|
82
|
-
let isUsingCache = false;
|
|
83
|
-
const cacheInfo = {
|
|
84
|
-
ds: props.dataSource,
|
|
56
|
+
return await (0, _func_grid.ApplyDataSource)(props.dataSource, {
|
|
85
57
|
skip: dt.skip,
|
|
86
|
-
limit: dt.limit
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
91
|
-
cached_data.current = undefined;
|
|
92
|
-
last_cache_info.current = cacheInfo;
|
|
93
|
-
}
|
|
94
|
-
if (cached_data.current) {
|
|
95
|
-
//cache is valid, use the cache
|
|
96
|
-
isUsingCache = true;
|
|
97
|
-
result_data = cached_data.current;
|
|
98
|
-
} else {
|
|
99
|
-
//cache is invalid, use the datasource again
|
|
100
|
-
isUsingCache = false;
|
|
101
|
-
if (typeof props.dataSource === 'function') {
|
|
102
|
-
result_data = await props.dataSource(dt);
|
|
103
|
-
} else result_data = props.dataSource;
|
|
104
|
-
}
|
|
105
|
-
//making sure the datasource is a valid object :
|
|
106
|
-
if (!result_data) result_data = [];
|
|
107
|
-
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
108
|
-
data: result_data
|
|
109
|
-
};
|
|
110
|
-
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
111
|
-
//no need to fix parent/child when using cache (it should be already fixed)
|
|
112
|
-
if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
|
|
113
|
-
if (!result_data.count) result_data.count = result_data.data.length;
|
|
114
|
-
//update cache
|
|
115
|
-
cached_data.current = result_data;
|
|
116
|
-
return result_data;
|
|
58
|
+
limit: dt.limit,
|
|
59
|
+
cached_data: cached_data,
|
|
60
|
+
last_cache_info: last_cache_info
|
|
61
|
+
});
|
|
117
62
|
}, [props.dataSource]);
|
|
118
63
|
const base_gridOptions = _react.default.useMemo(() => {
|
|
119
64
|
const firstcolumn = cached_columns[0];
|
|
120
|
-
const licenseKey = props.licenseKey || get_default_key();
|
|
65
|
+
const licenseKey = props.licenseKey || (0, _func_grid.get_default_key)();
|
|
121
66
|
const events = {
|
|
122
67
|
onSkipChange: props.onSkipChange,
|
|
123
68
|
onLimitChange: props.onLimitChange,
|
|
@@ -174,22 +119,22 @@ function DataGridEventsWrapper(props) {
|
|
|
174
119
|
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
175
120
|
/* --------------------------------- events --------------------------------- */
|
|
176
121
|
const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
|
|
177
|
-
if (
|
|
122
|
+
if (_func_child.func_selection.has_selection()) return;
|
|
178
123
|
update_menuRow(rowProps.data);
|
|
179
|
-
update_menuAnchorEl(
|
|
124
|
+
update_menuAnchorEl(_func_child.func_selection.getVirtualElement(event.clientX, event.clientY));
|
|
180
125
|
event.preventDefault();
|
|
181
126
|
}, []);
|
|
182
127
|
const onRowClick = _react.default.useCallback((rowProps, event) => {
|
|
183
128
|
const nowDate = Date.now();
|
|
184
|
-
const lastclick = click_data.current[get_row_id(rowProps)];
|
|
129
|
+
const lastclick = click_data.current[(0, _func_grid.get_row_id)(rowProps)];
|
|
185
130
|
if (lastclick) {
|
|
186
131
|
const diffTime = Math.abs(nowDate - lastclick);
|
|
187
132
|
if (diffTime < 400) {
|
|
188
|
-
click_data.current[get_row_id(rowProps)] = null;
|
|
133
|
+
click_data.current[(0, _func_grid.get_row_id)(rowProps)] = null;
|
|
189
134
|
return props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
|
|
190
135
|
}
|
|
191
136
|
}
|
|
192
|
-
click_data.current[get_row_id(rowProps)] = nowDate;
|
|
137
|
+
click_data.current[(0, _func_grid.get_row_id)(rowProps)] = nowDate;
|
|
193
138
|
return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
|
|
194
139
|
}, [props.onRowClick, props.onRowDoubleClick]);
|
|
195
140
|
_react.default.useEffect(() => {
|
|
@@ -219,18 +164,63 @@ function DataGridEventsWrapper(props) {
|
|
|
219
164
|
...events
|
|
220
165
|
};
|
|
221
166
|
}, [props.static_gridOptions, onRowClick]);
|
|
222
|
-
|
|
223
|
-
...props,
|
|
224
|
-
static_gridOptions: static_gridOptions
|
|
225
|
-
}, _react.default.createElement(_controls.ContextMenu, {
|
|
167
|
+
const contextMenu = _react.default.createElement(_controls.ContextMenu, {
|
|
226
168
|
menuAnchorEl: menuAnchorEl,
|
|
227
169
|
set_menuAnchorEl: update_menuAnchorEl,
|
|
228
170
|
menuRow: menuRow,
|
|
229
171
|
menu_items: props.contextMenuItems
|
|
230
|
-
})
|
|
172
|
+
});
|
|
173
|
+
if (props.details_dataSource) {
|
|
174
|
+
return _react.default.createElement(DataGridDetailsWrapper, {
|
|
175
|
+
...props,
|
|
176
|
+
static_gridOptions: static_gridOptions
|
|
177
|
+
}, contextMenu, props.children);
|
|
178
|
+
} else {
|
|
179
|
+
return _react.default.createElement(DataGridSizeWrapper, {
|
|
180
|
+
...props,
|
|
181
|
+
static_gridOptions: static_gridOptions
|
|
182
|
+
}, contextMenu, props.children);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function DataGridDetailsWrapper(props) {
|
|
186
|
+
const cached_details_columns = _react.default.useMemo(() => {
|
|
187
|
+
return (0, _func_grid.ApplyColumnData)(props.details_columns);
|
|
188
|
+
}, [props.details_columns]);
|
|
189
|
+
const cached_data = _react.default.useRef();
|
|
190
|
+
const last_cache_info = _react.default.useRef();
|
|
191
|
+
const dataSource = _react.default.useCallback(async dt => {
|
|
192
|
+
const res = await (0, _func_grid.ApplyDataSource)(props.details_dataSource, {
|
|
193
|
+
skip: dt.skip,
|
|
194
|
+
limit: dt.limit,
|
|
195
|
+
cached_data: cached_data,
|
|
196
|
+
last_cache_info: last_cache_info
|
|
197
|
+
});
|
|
198
|
+
console.log('ds', res);
|
|
199
|
+
return res;
|
|
200
|
+
}, [props.dataSource]);
|
|
201
|
+
const renderDetailsGrid = ({
|
|
202
|
+
data
|
|
203
|
+
}) => {
|
|
204
|
+
return _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
205
|
+
defaultFilterValue: props.details_filter,
|
|
206
|
+
dataSource: dataSource,
|
|
207
|
+
columns: cached_details_columns
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Merge details into grid
|
|
212
|
+
*/
|
|
213
|
+
const static_gridOptions = _react.default.useMemo(() => {
|
|
214
|
+
const finalresult = props.static_gridOptions || {};
|
|
215
|
+
finalresult['renderDetailsGrid'] = renderDetailsGrid;
|
|
216
|
+
return finalresult;
|
|
217
|
+
}, [props.static_gridOptions]);
|
|
218
|
+
return _react.default.createElement(DataGridSizeWrapper, {
|
|
219
|
+
...props,
|
|
220
|
+
static_gridOptions: static_gridOptions
|
|
221
|
+
}, props.children);
|
|
231
222
|
}
|
|
232
223
|
function DataGridSizeWrapper(props) {
|
|
233
|
-
// console.log(props);
|
|
234
224
|
if (props.delayedSize) {
|
|
235
225
|
return _react.default.createElement(DataGridDelayedSize, {
|
|
236
226
|
...props
|
|
@@ -241,6 +231,7 @@ function DataGridSizeWrapper(props) {
|
|
|
241
231
|
});
|
|
242
232
|
}
|
|
243
233
|
}
|
|
234
|
+
/* -------------------------------------------------------------------------- */
|
|
244
235
|
function DataGridDelayedSize(props) {
|
|
245
236
|
const {
|
|
246
237
|
ref,
|
|
@@ -279,216 +270,6 @@ function DataGridFlexSize(props) {
|
|
|
279
270
|
/* -------------------------------------------------------------------------- */
|
|
280
271
|
/* -------------------------------------------------------------------------- */
|
|
281
272
|
/* -------------------------------------------------------------------------- */
|
|
282
|
-
/**
|
|
283
|
-
* merges together all different props for columns
|
|
284
|
-
* to build a single final column data array
|
|
285
|
-
* @param props
|
|
286
|
-
* @returns
|
|
287
|
-
*/
|
|
288
|
-
function ApplyColumnData(props) {
|
|
289
|
-
const final_columns = [];
|
|
290
|
-
let mcols = props.columns || [];
|
|
291
|
-
let mcolExts = props.columnExtensions || [];
|
|
292
|
-
let rightColumns = props.rightColumns || [];
|
|
293
|
-
let leftColumns = props.leftColumns || [];
|
|
294
|
-
let editableColumns = props.editableColumns || [];
|
|
295
|
-
let customColumns = props.customColumns || [];
|
|
296
|
-
if (!Array.isArray(mcols)) return [];
|
|
297
|
-
/* ------------------------------- fix columns ------------------------------ */
|
|
298
|
-
mcols.map(r => {
|
|
299
|
-
if (r == null) return null;
|
|
300
|
-
if (typeof r === 'string') return {
|
|
301
|
-
field: r,
|
|
302
|
-
header: r
|
|
303
|
-
};
|
|
304
|
-
if (typeof r === 'object') {
|
|
305
|
-
let final_cl = {
|
|
306
|
-
name: get_col_name(r),
|
|
307
|
-
header: get_col_header(r),
|
|
308
|
-
width: r.width || undefined
|
|
309
|
-
};
|
|
310
|
-
final_cl = {
|
|
311
|
-
...defaultColumnOptions,
|
|
312
|
-
...r,
|
|
313
|
-
...final_cl
|
|
314
|
-
};
|
|
315
|
-
return final_cl;
|
|
316
|
-
}
|
|
317
|
-
return null;
|
|
318
|
-
}).forEach(r => {
|
|
319
|
-
if (r != null) final_columns.push(r);
|
|
320
|
-
});
|
|
321
|
-
/* ---------------------------- apply extensions ---------------------------- */
|
|
322
|
-
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
323
|
-
const ext = mcolExts[index];
|
|
324
|
-
const ext_cl = get_col_name(ext);
|
|
325
|
-
if (!ext_cl) {
|
|
326
|
-
console.warn('ColumnExtension must have a name');
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
|
|
330
|
-
if (mcol) {
|
|
331
|
-
for (const key in ext) {
|
|
332
|
-
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
336
|
-
}
|
|
337
|
-
/* ------------------------------- frozen cols ------------------------------ */
|
|
338
|
-
if (Array.isArray(leftColumns)) {
|
|
339
|
-
for (let index = 0; index < leftColumns.length; index++) {
|
|
340
|
-
const r = get_col_name(leftColumns[index]);
|
|
341
|
-
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
342
|
-
if (mcol) {
|
|
343
|
-
mcol.locked = 'start';
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (Array.isArray(rightColumns)) {
|
|
348
|
-
for (let index = 0; index < rightColumns.length; index++) {
|
|
349
|
-
const r = get_col_name(rightColumns[index]);
|
|
350
|
-
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
351
|
-
if (mcol) {
|
|
352
|
-
mcol.locked = 'end';
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
/* -------------------------------- ediatable ------------------------------- */
|
|
357
|
-
if (Array.isArray(editableColumns)) {
|
|
358
|
-
for (let index = 0; index < editableColumns.length; index++) {
|
|
359
|
-
const r = get_col_name(editableColumns[index]);
|
|
360
|
-
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
361
|
-
if (mcol) {
|
|
362
|
-
mcol.editable = true;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
for (let index = 0; index < final_columns.length; index++) {
|
|
367
|
-
const col = final_columns[index];
|
|
368
|
-
if (col.type) {
|
|
369
|
-
switch (col.type) {
|
|
370
|
-
case 'combo':
|
|
371
|
-
case 'select':
|
|
372
|
-
//@ts-ignore
|
|
373
|
-
col.editor = _SelectEditor.default;
|
|
374
|
-
break;
|
|
375
|
-
case 'number':
|
|
376
|
-
case 'numberic':
|
|
377
|
-
//@ts-ignore
|
|
378
|
-
col.editor = _NumericEditor.default;
|
|
379
|
-
break;
|
|
380
|
-
case 'truefalse':
|
|
381
|
-
case 'bool':
|
|
382
|
-
//@ts-ignore
|
|
383
|
-
col.editor = _BoolEditor.default;
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
if (col.editable != false) col.editable = true;
|
|
387
|
-
delete col.type;
|
|
388
|
-
}
|
|
389
|
-
//@ts-ignore
|
|
390
|
-
if (!col.editorProps) col.editorProps = {};
|
|
391
|
-
if (col.items) {
|
|
392
|
-
//@ts-ignore
|
|
393
|
-
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
394
|
-
//@ts-ignore
|
|
395
|
-
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
396
|
-
//@ts-ignore
|
|
397
|
-
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
398
|
-
delete col.items;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
/* -------------------------------------------------------------------------- */
|
|
402
|
-
if (Array.isArray(customColumns)) {
|
|
403
|
-
for (let index = 0; index < customColumns.length; index++) {
|
|
404
|
-
const r = customColumns[index];
|
|
405
|
-
const rn = get_col_name(r);
|
|
406
|
-
const mcol = final_columns.find(s => get_col_name(s) === rn);
|
|
407
|
-
if (mcol) {
|
|
408
|
-
//@ts-ignore
|
|
409
|
-
mcol.render = r.render;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
/* ------------------------------ apply renames ----------------------------- */
|
|
414
|
-
for (let index = 0; index < final_columns.length; index++) {
|
|
415
|
-
const col = final_columns[index];
|
|
416
|
-
if (!col.name) {
|
|
417
|
-
col.name = get_col_name(col);
|
|
418
|
-
delete col.field;
|
|
419
|
-
delete col.key;
|
|
420
|
-
delete col.columnName;
|
|
421
|
-
if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
/* -------------------------------------------------------------------------- */
|
|
425
|
-
//console.log(final_columns);
|
|
426
|
-
return final_columns;
|
|
427
|
-
}
|
|
428
|
-
function to_datasource(arr, idProperty, valueAsID = true) {
|
|
429
|
-
const res = [];
|
|
430
|
-
let index = 0;
|
|
431
|
-
if (Array.isArray(arr)) {
|
|
432
|
-
arr.map(s => {
|
|
433
|
-
let elem = {};
|
|
434
|
-
if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
|
|
435
|
-
if (typeof s === 'object') elem = {
|
|
436
|
-
...elem,
|
|
437
|
-
...s
|
|
438
|
-
};else elem['label'] = s;
|
|
439
|
-
res.push(elem);
|
|
440
|
-
index++;
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
return res;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Gets name of a column from its column object
|
|
447
|
-
* @param obj
|
|
448
|
-
* @returns
|
|
449
|
-
*/
|
|
450
|
-
function get_col_name(obj) {
|
|
451
|
-
if (!obj) return '';
|
|
452
|
-
if (typeof obj == 'string') return obj;
|
|
453
|
-
if (typeof obj != 'object') return '';
|
|
454
|
-
return obj.name || obj.field || obj.key || obj.columnName || '';
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Gets header of a column
|
|
458
|
-
* @param obj
|
|
459
|
-
* @returns
|
|
460
|
-
*/
|
|
461
|
-
function get_col_header(obj) {
|
|
462
|
-
if (!obj) return '';
|
|
463
|
-
if (typeof obj == 'string') return obj;
|
|
464
|
-
if (typeof obj != 'object') return '';
|
|
465
|
-
return obj.header || obj.title || get_col_name(obj);
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Gets name of a column from its column object
|
|
469
|
-
* @param obj
|
|
470
|
-
* @returns
|
|
471
|
-
*/
|
|
472
|
-
function get_row_id(obj) {
|
|
473
|
-
if (!obj) return '-1';
|
|
474
|
-
if (typeof obj == 'string') return obj;
|
|
475
|
-
if (typeof obj != 'object') return '-1';
|
|
476
|
-
return obj.__table_id || obj.id || '-1';
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Gets default activation key for grid plugin
|
|
480
|
-
* @returns
|
|
481
|
-
*/
|
|
482
|
-
function get_default_key() {
|
|
483
|
-
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
484
|
-
}
|
|
485
|
-
//check if two cache objects are the same
|
|
486
|
-
function validateCache(current, old, looseCheck = false) {
|
|
487
|
-
if (!old || !(0, _object.object_equals)(current, old)) return false;
|
|
488
|
-
if (looseCheck) return true;
|
|
489
|
-
if (current.ds != old.ds) return false;
|
|
490
|
-
return true;
|
|
491
|
-
}
|
|
492
273
|
/* -------------------------------------------------------------------------- */
|
|
493
274
|
var _default = AzGrid;
|
|
494
275
|
exports.default = _default;
|
package/package.json
CHANGED
package/src/example.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { getFormControlUtilityClasses } from '@mui/material';
|
|
|
9
9
|
const columns = [
|
|
10
10
|
{
|
|
11
11
|
name: 'name',
|
|
12
|
-
title: '
|
|
12
|
+
title: 'Name',
|
|
13
13
|
defaultFlex: 1,
|
|
14
14
|
},
|
|
15
15
|
{
|
|
@@ -29,10 +29,10 @@ const columns = [
|
|
|
29
29
|
const editableColumns = ['job', 'age'];
|
|
30
30
|
const contextMenuItems = ['test'];
|
|
31
31
|
|
|
32
|
-
function getData(delta: any) {
|
|
32
|
+
function getData(delta: any, max = 200) {
|
|
33
33
|
const fd: any[] = [];
|
|
34
34
|
console.log('Delta:', delta);
|
|
35
|
-
for (let index = 0; index <
|
|
35
|
+
for (let index = 0; index < max; index++) {
|
|
36
36
|
const currentObject = {
|
|
37
37
|
__table_id: String(index),
|
|
38
38
|
name: 'user-' + index,
|
|
@@ -71,6 +71,7 @@ function getData(delta: any) {
|
|
|
71
71
|
export function ExampleGrid() {
|
|
72
72
|
const [ds_reset, set_ds_reset] = React.useState(0);
|
|
73
73
|
const [delta, set_delta] = React.useState({});
|
|
74
|
+
const [delayed_reload, set_delayed_reload] = React.useState(false);
|
|
74
75
|
|
|
75
76
|
const dataSource = React.useCallback(
|
|
76
77
|
async (dt) => {
|
|
@@ -83,6 +84,17 @@ export function ExampleGrid() {
|
|
|
83
84
|
},
|
|
84
85
|
[ds_reset, delta]
|
|
85
86
|
);
|
|
87
|
+
const details_dataSource = React.useCallback(
|
|
88
|
+
async (dt) => {
|
|
89
|
+
//console.log('Start loading');
|
|
90
|
+
return await new Promise((resolve) => {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
resolve(getData(delta, 5));
|
|
93
|
+
}, 1000);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
[ds_reset, delta]
|
|
97
|
+
);
|
|
86
98
|
|
|
87
99
|
function onEditComplete(params) {
|
|
88
100
|
const { value, columnId, rowId, ...rest } = params;
|
|
@@ -101,22 +113,29 @@ export function ExampleGrid() {
|
|
|
101
113
|
//console.log(rowdata?.data || rowdata);
|
|
102
114
|
}, []);
|
|
103
115
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
set_delayed_reload(true);
|
|
119
|
+
}, 2000);
|
|
120
|
+
}, []);
|
|
121
|
+
const customColumns = React.useMemo(() => {
|
|
122
|
+
if (!delayed_reload) return [];
|
|
123
|
+
return [{ name: 'name', render: (r) => r.value + '^' }];
|
|
124
|
+
}, [delayed_reload]);
|
|
108
125
|
|
|
109
126
|
return (
|
|
110
127
|
<AzGrid
|
|
111
128
|
dark
|
|
112
129
|
delayedSize
|
|
130
|
+
details_dataSource={details_dataSource}
|
|
131
|
+
details_columns={columns}
|
|
113
132
|
onRowClick={onRowClick}
|
|
114
133
|
onRowDoubleClick={onRowDoubleClick}
|
|
115
134
|
// allowChildRows
|
|
116
135
|
// onSelectionChange={onSelectionChange}
|
|
117
136
|
// selected={selected}
|
|
118
137
|
contextMenuItems={contextMenuItems}
|
|
119
|
-
|
|
138
|
+
customColumns={customColumns}
|
|
120
139
|
columns={columns}
|
|
121
140
|
editableColumns={editableColumns}
|
|
122
141
|
editable={true}
|
|
@@ -10,22 +10,26 @@ function get_selfId(obj) {
|
|
|
10
10
|
//given an array of rows, fixes parent,child relations
|
|
11
11
|
export function fix_parent_child_relations<T extends mrow>(rows: T[]): T[] {
|
|
12
12
|
if (!Array.isArray(rows)) rows = [];
|
|
13
|
+
const anyparentid = rows.find((r) => get_parentId(r));
|
|
14
|
+
const anyselfid = rows.find((r) => get_selfId(r));
|
|
15
|
+
if (!anyparentid || !anyselfid) return rows;
|
|
13
16
|
|
|
14
17
|
const converted_rows: converted_row[] = rows
|
|
15
18
|
.filter((r) => r != null)
|
|
16
19
|
.map((r) => {
|
|
17
20
|
return { parent: get_parentId(r), self: get_selfId(r), data: r };
|
|
18
21
|
});
|
|
19
|
-
const top_level_rows: converted_row[] = converted_rows.filter((r) => !r.parent);
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const top_level_rows: converted_row[] = converted_rows.filter((r) => !r.parent);
|
|
24
|
+
const any_child = converted_rows.find((r) => Boolean(r.parent));
|
|
25
|
+
if (any_child) {
|
|
26
|
+
//find children of top-level parents:
|
|
27
|
+
for (let index = 0; index < top_level_rows.length; index++) {
|
|
28
|
+
const mrow = top_level_rows[index];
|
|
29
|
+
assign_children(mrow, converted_rows);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
//console.log(result);
|
|
28
|
-
return result;
|
|
32
|
+
return top_level_rows.map((r) => r.data) as T[];
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
function assign_children(row: converted_row, all_rows: converted_row[]) {
|
|
@@ -37,7 +41,8 @@ function assign_children(row: converted_row, all_rows: converted_row[]) {
|
|
|
37
41
|
assign_children(child, all_rows);
|
|
38
42
|
}
|
|
39
43
|
row.data.__children = my_children.map((r) => r.data);
|
|
40
|
-
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0)
|
|
44
|
+
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0)
|
|
45
|
+
row.data.__children = undefined;
|
|
41
46
|
}
|
|
42
47
|
export class func_selection {
|
|
43
48
|
static getVirtualElement(x = 0, y = 0) {
|
|
@@ -59,7 +64,10 @@ export class func_selection {
|
|
|
59
64
|
var text: any = '';
|
|
60
65
|
if (window.getSelection) {
|
|
61
66
|
text = window.getSelection()?.toString();
|
|
62
|
-
} else if (
|
|
67
|
+
} else if (
|
|
68
|
+
(document as any).selection &&
|
|
69
|
+
(document as any).selection.type != 'Control'
|
|
70
|
+
) {
|
|
63
71
|
text = (document as any).selection.createRange()?.text;
|
|
64
72
|
}
|
|
65
73
|
return text || '';
|