@azrico/reactgrid 1.1.14 → 1.1.15
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/dist/index.js +21 -3
- package/dist/src/example.js +130 -95
- package/dist/src/func/helpers.js +80 -75
- package/dist/src/index.js +30 -5
- package/dist/src/themes/base_styles.css +26 -0
- package/dist/src/themes/grid.css +20 -0
- package/dist/src/views/DataGrid.d.ts +3 -1
- package/dist/src/views/DataGrid.js +409 -394
- package/dist/src/views/index.js +23 -3
- package/package.json +2 -2
- package/src/example.tsx +8 -0
- package/src/index.tsx +7 -3
- package/src/views/DataGrid.tsx +34 -17
|
@@ -1,414 +1,429 @@
|
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AzGrid = AzGrid;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
require("@inovua/reactdatagrid-enterprise/index.css");
|
|
9
|
+
require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
|
|
10
|
+
require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
|
|
11
|
+
require("../themes/base_styles.css");
|
|
12
|
+
require("../themes/grid.css");
|
|
13
|
+
var _controls = require("@azrico/controls");
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
var _helpers = require("../func/helpers");
|
|
16
|
+
var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
|
|
17
|
+
var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
|
|
18
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
19
|
+
var _object = require("@azrico/object");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
/* -------------------------------------------------------------------------- */
|
|
22
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
23
|
+
// string: {
|
|
24
|
+
// type: 'string',
|
|
25
|
+
// emptyValue: '',
|
|
26
|
+
// operators: [
|
|
27
|
+
// {
|
|
28
|
+
// name: 'contains',
|
|
29
|
+
// fn: ({ value, filterValue, data }) => {
|
|
30
|
+
// console.log('fn');
|
|
31
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
32
|
+
// },
|
|
33
|
+
// },
|
|
34
|
+
// ],
|
|
35
|
+
// },
|
|
36
|
+
// };
|
|
37
|
+
const defaultOptions = {
|
|
38
|
+
//filterTypes: defaultfilterTypes,
|
|
39
|
+
remoteFilter: false,
|
|
40
|
+
remoteSort: false,
|
|
41
|
+
editStartEvent: 'click',
|
|
42
|
+
rowReorderColumn: false,
|
|
43
|
+
resizable: true,
|
|
44
|
+
rowIndexColumn: true
|
|
45
|
+
};
|
|
46
|
+
const forcedOptions = {
|
|
47
|
+
idProperty: '__table_id',
|
|
48
|
+
nodesProperty: '__children'
|
|
49
|
+
};
|
|
50
|
+
const defaultColumnOptions = {
|
|
51
|
+
draggable: false,
|
|
52
|
+
lockable: false
|
|
53
|
+
};
|
|
54
|
+
const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
|
|
55
|
+
/* -------------------------------------------------------------------------- */
|
|
56
|
+
function AzGrid(props) {
|
|
57
|
+
/* -------------------------------------------------------------------------- */
|
|
58
|
+
/* Columns */
|
|
59
|
+
/* -------------------------------------------------------------------------- */
|
|
60
|
+
const cached_columns = _react.default.useMemo(() => {
|
|
61
|
+
return ApplyColumnData(props);
|
|
62
|
+
}, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
|
|
63
|
+
/* -------------------------------------------------------------------------- */
|
|
64
|
+
/* Row changes */
|
|
65
|
+
/* -------------------------------------------------------------------------- */
|
|
66
|
+
const cached_data = _react.default.useRef();
|
|
67
|
+
const last_cache_info = _react.default.useRef();
|
|
68
|
+
const dataSource = _react.default.useCallback(async dt => {
|
|
69
|
+
let result_data = undefined;
|
|
70
|
+
let isUsingCache = false;
|
|
71
|
+
const cacheInfo = {
|
|
72
|
+
ds: props.dataSource,
|
|
73
|
+
skip: dt.skip,
|
|
74
|
+
limit: dt.limit
|
|
75
|
+
};
|
|
76
|
+
//check if we can used cached data
|
|
77
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
78
|
+
if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
79
|
+
cached_data.current = undefined;
|
|
80
|
+
last_cache_info.current = cacheInfo;
|
|
81
|
+
}
|
|
82
|
+
if (cached_data.current) {
|
|
83
|
+
//cache is valid, use the cache
|
|
84
|
+
isUsingCache = true;
|
|
85
|
+
result_data = cached_data.current;
|
|
86
|
+
} else {
|
|
87
|
+
//cache is invalid, use the datasource again
|
|
88
|
+
isUsingCache = false;
|
|
89
|
+
if (typeof props.dataSource === 'function') {
|
|
90
|
+
result_data = await props.dataSource(dt);
|
|
91
|
+
} else result_data = props.dataSource;
|
|
92
|
+
}
|
|
93
|
+
//making sure the datasource is a valid object :
|
|
94
|
+
if (!result_data) result_data = [];
|
|
95
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
96
|
+
data: result_data
|
|
97
|
+
};
|
|
98
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
99
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
100
|
+
if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
|
|
101
|
+
if (!result_data.count) result_data.count = result_data.data.length;
|
|
102
|
+
//update cache
|
|
103
|
+
cached_data.current = result_data;
|
|
104
|
+
return result_data;
|
|
105
|
+
}, [props.dataSource]);
|
|
106
|
+
return _react.default.createElement(DataGrid, {
|
|
107
|
+
...props,
|
|
108
|
+
columns: cached_columns,
|
|
109
|
+
dataSource: dataSource,
|
|
110
|
+
highlightedRow: props.highlightedRow
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/* -------------------------------------------------------------------------- */
|
|
114
|
+
function DataGrid(props) {
|
|
115
|
+
const {
|
|
116
|
+
columns,
|
|
117
|
+
dataSource,
|
|
118
|
+
dark,
|
|
119
|
+
contextMenuItems
|
|
120
|
+
} = props;
|
|
121
|
+
/* -------------------------------------------------------------------------- */
|
|
122
|
+
const gridRef = _react.default.useRef(null);
|
|
123
|
+
const click_data = _react.default.useRef(null);
|
|
124
|
+
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
125
|
+
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
126
|
+
_react.default.useEffect(() => {
|
|
127
|
+
click_data.current = {};
|
|
128
|
+
}, [dataSource]);
|
|
129
|
+
/* --------------------------------- events --------------------------------- */
|
|
130
|
+
const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
|
|
131
|
+
if (_helpers.func_selection.has_selection()) return;
|
|
132
|
+
update_menuRow(rowProps.data);
|
|
133
|
+
update_menuAnchorEl(_helpers.func_selection.getVirtualElement(event.clientX, event.clientY));
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
}, []);
|
|
136
|
+
const onRowClick = _react.default.useCallback((rowProps, event) => {
|
|
137
|
+
const nowDate = Date.now();
|
|
138
|
+
const lastclick = click_data.current[get_row_id(rowProps)];
|
|
139
|
+
if (lastclick) {
|
|
140
|
+
const diffTime = Math.abs(nowDate - lastclick);
|
|
141
|
+
if (diffTime < 400) {
|
|
142
|
+
props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
click_data.current[get_row_id(rowProps)] = nowDate;
|
|
146
|
+
props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
|
|
147
|
+
}, []);
|
|
148
|
+
/* ------------------------------- ContextMenu ------------------------------ */
|
|
149
|
+
const update_menuAnchorEl = _react.default.useCallback(el => {
|
|
150
|
+
if (el) {
|
|
151
|
+
set_menuAnchorEl(el);
|
|
152
|
+
} else set_menuAnchorEl(null);
|
|
153
|
+
}, []);
|
|
154
|
+
const update_menuRow = _react.default.useCallback(r => {
|
|
155
|
+
if (r) {
|
|
156
|
+
set_menuRow(r);
|
|
157
|
+
} else set_menuRow(null);
|
|
158
|
+
}, []);
|
|
159
|
+
/* -------------------------------------------------------------------------- */
|
|
160
|
+
/* Create the grid */
|
|
161
|
+
/* -------------------------------------------------------------------------- */
|
|
162
|
+
const base_gridOptions = _react.default.useMemo(() => {
|
|
163
|
+
const firstcolumn = columns[0];
|
|
164
|
+
const licenseKey = props.licenseKey || get_default_key();
|
|
165
|
+
const events = {
|
|
166
|
+
onRowClick: onRowClick,
|
|
167
|
+
onRowContextMenu: onRowContextMenu,
|
|
168
|
+
onSkipChange: props.onSkipChange,
|
|
169
|
+
onLimitChange: props.onLimitChange,
|
|
170
|
+
onEditComplete: props.onEditComplete
|
|
171
|
+
};
|
|
172
|
+
const extra_ops = {
|
|
173
|
+
onSelectionChange: props.onSelectionChange,
|
|
174
|
+
licenseKey: licenseKey,
|
|
175
|
+
editable: props.editable,
|
|
176
|
+
treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
|
|
177
|
+
renderRowDetails: props.RowDetail,
|
|
178
|
+
theme: dark ? 'amber-dark' : 'default-light'
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
...defaultOptions,
|
|
182
|
+
...events,
|
|
183
|
+
...extra_ops
|
|
184
|
+
};
|
|
185
|
+
}, [columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
|
|
186
|
+
const static_gridOptions = _react.default.useMemo(() => {
|
|
187
|
+
return {
|
|
188
|
+
...base_gridOptions,
|
|
189
|
+
...props.gridOptions,
|
|
190
|
+
...forcedOptions
|
|
191
|
+
};
|
|
192
|
+
}, [props.gridOptions, base_gridOptions, forcedOptions]);
|
|
193
|
+
const dynamic_gridOptions = _react.default.useMemo(() => {
|
|
194
|
+
const res = {};
|
|
195
|
+
dynamic_option_names.map(r => {
|
|
196
|
+
res[r] = props[r];
|
|
197
|
+
});
|
|
198
|
+
return res;
|
|
199
|
+
}, dynamic_option_names.map(r => props[r]));
|
|
200
|
+
// const { width, height, ref: resize_ref } = useResizeDetector();
|
|
201
|
+
return _react.default.createElement("div", {
|
|
202
|
+
className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
|
|
203
|
+
}, _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
204
|
+
...static_gridOptions,
|
|
205
|
+
...dynamic_gridOptions,
|
|
206
|
+
handle: ref => gridRef.current = ref ? ref.current : null,
|
|
207
|
+
className: 'azgrid-filler',
|
|
208
|
+
columns: columns,
|
|
209
|
+
dataSource: dataSource
|
|
210
|
+
}), _react.default.createElement(_controls.ContextMenu, {
|
|
211
|
+
menuAnchorEl: menuAnchorEl,
|
|
212
|
+
set_menuAnchorEl: update_menuAnchorEl,
|
|
213
|
+
menuRow: menuRow,
|
|
214
|
+
items: contextMenuItems
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
/* -------------------------------------------------------------------------- */
|
|
218
|
+
/* -------------------------------------------------------------------------- */
|
|
219
|
+
/* -------------------------------------------------------------------------- */
|
|
220
|
+
/* -------------------------------------------------------------------------- */
|
|
197
221
|
/**
|
|
198
222
|
* merges together all different props for columns
|
|
199
223
|
* to build a single final column data array
|
|
200
224
|
* @param props
|
|
201
225
|
* @returns
|
|
202
|
-
*/
|
|
203
|
-
function ApplyColumnData(props) {
|
|
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
|
-
}
|
|
226
|
+
*/
|
|
227
|
+
function ApplyColumnData(props) {
|
|
228
|
+
const final_columns = [];
|
|
229
|
+
let mcols = props.columns || [];
|
|
230
|
+
let mcolExts = props.columnExtensions || [];
|
|
231
|
+
let rightColumns = props.rightColumns || [];
|
|
232
|
+
let leftColumns = props.leftColumns || [];
|
|
233
|
+
let editableColumns = props.editableColumns || [];
|
|
234
|
+
let customColumns = props.customColumns || [];
|
|
235
|
+
if (!Array.isArray(mcols)) return [];
|
|
236
|
+
/* ------------------------------- fix columns ------------------------------ */
|
|
237
|
+
mcols.map(r => {
|
|
238
|
+
if (r == null) return null;
|
|
239
|
+
if (typeof r === 'string') return {
|
|
240
|
+
field: r,
|
|
241
|
+
header: r
|
|
242
|
+
};
|
|
243
|
+
if (typeof r === 'object') {
|
|
244
|
+
let final_cl = {
|
|
245
|
+
name: get_col_name(r),
|
|
246
|
+
header: get_col_header(r),
|
|
247
|
+
width: r.width || undefined
|
|
248
|
+
};
|
|
249
|
+
final_cl = {
|
|
250
|
+
...defaultColumnOptions,
|
|
251
|
+
...r,
|
|
252
|
+
...final_cl
|
|
253
|
+
};
|
|
254
|
+
return final_cl;
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}).forEach(r => {
|
|
258
|
+
if (r != null) final_columns.push(r);
|
|
259
|
+
});
|
|
260
|
+
/* ---------------------------- apply extensions ---------------------------- */
|
|
261
|
+
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
262
|
+
const ext = mcolExts[index];
|
|
263
|
+
const ext_cl = get_col_name(ext);
|
|
264
|
+
const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
|
|
265
|
+
if (mcol) {
|
|
266
|
+
for (const key in ext) {
|
|
267
|
+
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
271
|
+
}
|
|
272
|
+
/* ------------------------------- frozen cols ------------------------------ */
|
|
273
|
+
if (Array.isArray(leftColumns)) {
|
|
274
|
+
for (let index = 0; index < leftColumns.length; index++) {
|
|
275
|
+
const r = get_col_name(leftColumns[index]);
|
|
276
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
277
|
+
if (mcol) {
|
|
278
|
+
mcol.locked = 'start';
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (Array.isArray(rightColumns)) {
|
|
283
|
+
for (let index = 0; index < rightColumns.length; index++) {
|
|
284
|
+
const r = get_col_name(rightColumns[index]);
|
|
285
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
286
|
+
if (mcol) {
|
|
287
|
+
mcol.locked = 'end';
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/* -------------------------------- ediatable ------------------------------- */
|
|
292
|
+
if (Array.isArray(editableColumns)) {
|
|
293
|
+
for (let index = 0; index < editableColumns.length; index++) {
|
|
294
|
+
const r = get_col_name(editableColumns[index]);
|
|
295
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
296
|
+
if (mcol) {
|
|
297
|
+
// mcol.editor = editorWrapper;
|
|
298
|
+
// mcol.editorOptions = {
|
|
299
|
+
// editOnClick: true,
|
|
300
|
+
// };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
305
|
+
const col = final_columns[index];
|
|
306
|
+
if (col.type) {
|
|
307
|
+
switch (col.type) {
|
|
308
|
+
case 'combo':
|
|
309
|
+
case 'select':
|
|
310
|
+
//@ts-ignore
|
|
311
|
+
col.editor = _SelectEditor.default;
|
|
312
|
+
break;
|
|
313
|
+
//case 'number':
|
|
314
|
+
//case 'numberic':
|
|
315
|
+
// col.editor = NumericEditor;
|
|
316
|
+
// break;
|
|
317
|
+
//case 'truefalse':
|
|
318
|
+
//case 'bool':
|
|
319
|
+
// col.editor = BoolEditor;
|
|
320
|
+
// break;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
delete col.type;
|
|
324
|
+
}
|
|
325
|
+
//@ts-ignore
|
|
326
|
+
if (!col.editorProps) col.editorProps = {};
|
|
327
|
+
if (col.items) {
|
|
328
|
+
//@ts-ignore
|
|
329
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
330
|
+
//@ts-ignore
|
|
331
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
332
|
+
//@ts-ignore
|
|
333
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
334
|
+
delete col.items;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/* -------------------------------------------------------------------------- */
|
|
338
|
+
if (Array.isArray(customColumns)) {
|
|
339
|
+
for (let index = 0; index < customColumns.length; index++) {
|
|
340
|
+
const r = customColumns[index];
|
|
341
|
+
const rn = get_col_name(r);
|
|
342
|
+
const mcol = final_columns.find(s => get_col_name(s) === rn);
|
|
343
|
+
if (mcol) {
|
|
344
|
+
//@ts-ignore
|
|
345
|
+
mcol.render = r.render;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/* ------------------------------ apply renames ----------------------------- */
|
|
350
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
351
|
+
const col = final_columns[index];
|
|
352
|
+
if (!col.name) {
|
|
353
|
+
col.name = get_col_name(col);
|
|
354
|
+
delete col.field;
|
|
355
|
+
delete col.key;
|
|
356
|
+
delete col.columnName;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/* -------------------------------------------------------------------------- */
|
|
360
|
+
console.log(final_columns);
|
|
361
|
+
return final_columns;
|
|
362
|
+
}
|
|
363
|
+
function to_datasource(arr, idProperty) {
|
|
364
|
+
const res = [];
|
|
365
|
+
let index = 0;
|
|
366
|
+
if (Array.isArray(arr)) {
|
|
367
|
+
arr.map(s => {
|
|
368
|
+
let elem = {};
|
|
369
|
+
elem[idProperty] = '_cid_' + index;
|
|
370
|
+
if (typeof s === 'object') elem = {
|
|
371
|
+
...elem,
|
|
372
|
+
...s
|
|
373
|
+
};else elem['label'] = s;
|
|
374
|
+
res.push(elem);
|
|
375
|
+
index++;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return res;
|
|
379
|
+
}
|
|
354
380
|
/**
|
|
355
381
|
* Gets name of a column from its column object
|
|
356
382
|
* @param obj
|
|
357
383
|
* @returns
|
|
358
|
-
*/
|
|
359
|
-
function get_col_name(obj) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return 'default';
|
|
366
|
-
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
367
|
-
}
|
|
384
|
+
*/
|
|
385
|
+
function get_col_name(obj) {
|
|
386
|
+
if (!obj) return 'default';
|
|
387
|
+
if (typeof obj == 'string') return obj;
|
|
388
|
+
if (typeof obj != 'object') return 'default';
|
|
389
|
+
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
390
|
+
}
|
|
368
391
|
/**
|
|
369
392
|
* Gets header of a column
|
|
370
393
|
* @param obj
|
|
371
394
|
* @returns
|
|
372
|
-
*/
|
|
373
|
-
function get_col_header(obj) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return 'default';
|
|
380
|
-
return obj.header || obj.title || get_col_name(obj);
|
|
381
|
-
}
|
|
395
|
+
*/
|
|
396
|
+
function get_col_header(obj) {
|
|
397
|
+
if (!obj) return 'default';
|
|
398
|
+
if (typeof obj == 'string') return obj;
|
|
399
|
+
if (typeof obj != 'object') return 'default';
|
|
400
|
+
return obj.header || obj.title || get_col_name(obj);
|
|
401
|
+
}
|
|
382
402
|
/**
|
|
383
403
|
* Gets name of a column from its column object
|
|
384
404
|
* @param obj
|
|
385
405
|
* @returns
|
|
386
|
-
*/
|
|
387
|
-
function get_row_id(obj) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return 'default';
|
|
394
|
-
return obj.__table_id || obj.id || 'default';
|
|
395
|
-
}
|
|
406
|
+
*/
|
|
407
|
+
function get_row_id(obj) {
|
|
408
|
+
if (!obj) return 'default';
|
|
409
|
+
if (typeof obj == 'string') return obj;
|
|
410
|
+
if (typeof obj != 'object') return 'default';
|
|
411
|
+
return obj.__table_id || obj.id || 'default';
|
|
412
|
+
}
|
|
396
413
|
/**
|
|
397
414
|
* Gets default activation key for grid plugin
|
|
398
415
|
* @returns
|
|
399
|
-
*/
|
|
400
|
-
function get_default_key() {
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
//check if two cache objects are the same
|
|
404
|
-
function validateCache(current, old, looseCheck = false) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
/* -------------------------------------------------------------------------- */
|
|
414
|
-
export default AzGrid;
|
|
416
|
+
*/
|
|
417
|
+
function get_default_key() {
|
|
418
|
+
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
419
|
+
}
|
|
420
|
+
//check if two cache objects are the same
|
|
421
|
+
function validateCache(current, old, looseCheck = false) {
|
|
422
|
+
if (!old || !(0, _object.object_equals)(current, old)) return false;
|
|
423
|
+
if (looseCheck) return true;
|
|
424
|
+
if (current.ds != old.ds) return false;
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
/* -------------------------------------------------------------------------- */
|
|
428
|
+
var _default = AzGrid;
|
|
429
|
+
exports.default = _default;
|