@azrico/reactgrid 1.6.2 → 1.6.5
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 +33 -19
- package/README.md +165 -164
- package/__tests__/context-menu.config.cjs +14 -0
- package/__tests__/context-menu.test.js +150 -0
- package/config/generate-theme.cjs +1 -1
- package/config/theme-extras.css +11 -16
- package/dist/src/example.js +27 -2
- package/dist/src/func/func_a11y.d.ts +14 -0
- package/dist/src/func/func_a11y.js +63 -10
- package/dist/src/func/func_grid.d.ts +6 -0
- package/dist/src/func/func_grid.js +15 -4
- package/dist/src/hooks/useGridEvents.js +16 -4
- package/dist/src/themes/azgrid-theme.css +12 -17
- package/dist/src/types/types.d.ts +4 -0
- package/dist/src/views/DataGrid.js +10 -22
- package/package.json +1 -1
- package/src/example.tsx +202 -186
- package/src/func/func_a11y.ts +62 -4
- package/src/func/func_grid.ts +351 -340
- package/src/hooks/useGridEvents.ts +171 -158
- package/src/themes/azgrid-theme.css +12 -17
- package/src/types/types.ts +157 -153
- package/src/views/DataGrid.tsx +9 -17
package/src/func/func_grid.ts
CHANGED
|
@@ -1,340 +1,351 @@
|
|
|
1
|
-
import { ColumnDefinition, LooseColumnDefinition } from '../types/types';
|
|
2
|
-
|
|
3
|
-
import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
|
|
4
|
-
// import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
|
|
5
|
-
import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
|
|
6
|
-
import { fix_parent_child_relations } from './func_child';
|
|
7
|
-
import { object_equals } from '@azrico/object';
|
|
8
|
-
|
|
9
|
-
export type MakeWriteable<Type> = {
|
|
10
|
-
-readonly [Key in keyof Type]: Type[Key];
|
|
11
|
-
};
|
|
12
|
-
export type ModifyFields<T, R> = Omit<T, keyof R> & R;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export async function ApplyDataSource(
|
|
21
|
-
datasource,
|
|
22
|
-
props,
|
|
23
|
-
remote: { remoteFilter?: boolean; remoteSort?: boolean } = {}
|
|
24
|
-
) {
|
|
25
|
-
let result_data: any = undefined;
|
|
26
|
-
|
|
27
|
-
let isUsingCache = false;
|
|
28
|
-
|
|
29
|
-
//filter/sort are only part of the key when they are sent to a remote dataSource,
|
|
30
|
-
//local filtering/sorting keeps reusing the cached rows
|
|
31
|
-
const cacheInfo = {
|
|
32
|
-
ds: datasource,
|
|
33
|
-
skip: props.skip,
|
|
34
|
-
limit: props.limit,
|
|
35
|
-
filterValue: remote.remoteFilter ? props.filterValue : undefined,
|
|
36
|
-
sortInfo: remote.remoteSort ? props.sortInfo : undefined,
|
|
37
|
-
};
|
|
38
|
-
//check if we can used cached data
|
|
39
|
-
//if the datasource is changed since last render, we should invalidate cache
|
|
40
|
-
if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
41
|
-
props.cached_data.current = undefined;
|
|
42
|
-
props.last_cache_info.current = cacheInfo;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (props.cached_data.current) {
|
|
46
|
-
//cache is valid, use the cache
|
|
47
|
-
isUsingCache = true;
|
|
48
|
-
result_data = props.cached_data.current;
|
|
49
|
-
} else {
|
|
50
|
-
//cache is invalid, use the datasource again
|
|
51
|
-
|
|
52
|
-
isUsingCache = false;
|
|
53
|
-
if (typeof datasource === 'function') {
|
|
54
|
-
result_data = await datasource(props);
|
|
55
|
-
} else result_data = datasource;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//making sure the datasource is a valid object :
|
|
59
|
-
if (!result_data) result_data = [];
|
|
60
|
-
if (Array.isArray(result_data) || typeof result_data !== 'object')
|
|
61
|
-
result_data = { data: result_data };
|
|
62
|
-
|
|
63
|
-
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
64
|
-
|
|
65
|
-
//no need to fix parent/child when using cache (it should be already fixed)
|
|
66
|
-
if (!isUsingCache && props.allowChildRows) {
|
|
67
|
-
result_data.data = fix_parent_child_relations(result_data.data);
|
|
68
|
-
}
|
|
69
|
-
if (!result_data.count) {
|
|
70
|
-
result_data.count = (result_data.data as Array<any>).length;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
//update cache
|
|
74
|
-
props.cached_data.current = result_data;
|
|
75
|
-
return result_data;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* merges together all different props for columns
|
|
79
|
-
* to build a single final column data array
|
|
80
|
-
* @param column_data
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
export function applyColumnData(column_data: any): ColumnDefinition[] {
|
|
84
|
-
const final_columns: MakeWriteable<LooseColumnDefinition>[] = [];
|
|
85
|
-
if (!column_data) column_data = {};
|
|
86
|
-
if (Array.isArray(column_data)) column_data = { columns: column_data };
|
|
87
|
-
let mcols = column_data.columns || [];
|
|
88
|
-
let mcolExts = column_data.columnExtensions || [];
|
|
89
|
-
let rightColumns = column_data.rightColumns || [];
|
|
90
|
-
let leftColumns = column_data.leftColumns || [];
|
|
91
|
-
let editableColumns = column_data.editableColumns || [];
|
|
92
|
-
let customColumns = column_data.customColumns || [];
|
|
93
|
-
|
|
94
|
-
if (!Array.isArray(mcols)) return [];
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (
|
|
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
|
-
case '
|
|
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
|
-
return
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Gets
|
|
266
|
-
* @param obj
|
|
267
|
-
* @returns
|
|
268
|
-
*/
|
|
269
|
-
export function
|
|
270
|
-
if (!obj) return '';
|
|
271
|
-
if (typeof obj == 'string') return obj;
|
|
272
|
-
if (typeof obj != 'object') return '';
|
|
273
|
-
return obj.
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Gets
|
|
277
|
-
* @param obj
|
|
278
|
-
* @returns
|
|
279
|
-
*/
|
|
280
|
-
export function
|
|
281
|
-
if (
|
|
282
|
-
if (typeof obj
|
|
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
|
-
return
|
|
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
|
-
|
|
1
|
+
import { ColumnDefinition, LooseColumnDefinition } from '../types/types';
|
|
2
|
+
|
|
3
|
+
import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
|
|
4
|
+
// import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
|
|
5
|
+
import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
|
|
6
|
+
import { fix_parent_child_relations } from './func_child';
|
|
7
|
+
import { object_equals } from '@azrico/object';
|
|
8
|
+
|
|
9
|
+
export type MakeWriteable<Type> = {
|
|
10
|
+
-readonly [Key in keyof Type]: Type[Key];
|
|
11
|
+
};
|
|
12
|
+
export type ModifyFields<T, R> = Omit<T, keyof R> & R;
|
|
13
|
+
|
|
14
|
+
//editable is defaulted after types/extensions are applied, so they can tell if the consumer set it
|
|
15
|
+
const defaultColumnOptions: ColumnDefinition = {
|
|
16
|
+
draggable: false,
|
|
17
|
+
lockable: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function ApplyDataSource(
|
|
21
|
+
datasource,
|
|
22
|
+
props,
|
|
23
|
+
remote: { remoteFilter?: boolean; remoteSort?: boolean } = {}
|
|
24
|
+
) {
|
|
25
|
+
let result_data: any = undefined;
|
|
26
|
+
|
|
27
|
+
let isUsingCache = false;
|
|
28
|
+
|
|
29
|
+
//filter/sort are only part of the key when they are sent to a remote dataSource,
|
|
30
|
+
//local filtering/sorting keeps reusing the cached rows
|
|
31
|
+
const cacheInfo = {
|
|
32
|
+
ds: datasource,
|
|
33
|
+
skip: props.skip,
|
|
34
|
+
limit: props.limit,
|
|
35
|
+
filterValue: remote.remoteFilter ? props.filterValue : undefined,
|
|
36
|
+
sortInfo: remote.remoteSort ? props.sortInfo : undefined,
|
|
37
|
+
};
|
|
38
|
+
//check if we can used cached data
|
|
39
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
40
|
+
if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
41
|
+
props.cached_data.current = undefined;
|
|
42
|
+
props.last_cache_info.current = cacheInfo;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (props.cached_data.current) {
|
|
46
|
+
//cache is valid, use the cache
|
|
47
|
+
isUsingCache = true;
|
|
48
|
+
result_data = props.cached_data.current;
|
|
49
|
+
} else {
|
|
50
|
+
//cache is invalid, use the datasource again
|
|
51
|
+
|
|
52
|
+
isUsingCache = false;
|
|
53
|
+
if (typeof datasource === 'function') {
|
|
54
|
+
result_data = await datasource(props);
|
|
55
|
+
} else result_data = datasource;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//making sure the datasource is a valid object :
|
|
59
|
+
if (!result_data) result_data = [];
|
|
60
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object')
|
|
61
|
+
result_data = { data: result_data };
|
|
62
|
+
|
|
63
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
64
|
+
|
|
65
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
66
|
+
if (!isUsingCache && props.allowChildRows) {
|
|
67
|
+
result_data.data = fix_parent_child_relations(result_data.data);
|
|
68
|
+
}
|
|
69
|
+
if (!result_data.count) {
|
|
70
|
+
result_data.count = (result_data.data as Array<any>).length;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//update cache
|
|
74
|
+
props.cached_data.current = result_data;
|
|
75
|
+
return result_data;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* merges together all different props for columns
|
|
79
|
+
* to build a single final column data array
|
|
80
|
+
* @param column_data
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
export function applyColumnData(column_data: any): ColumnDefinition[] {
|
|
84
|
+
const final_columns: MakeWriteable<LooseColumnDefinition>[] = [];
|
|
85
|
+
if (!column_data) column_data = {};
|
|
86
|
+
if (Array.isArray(column_data)) column_data = { columns: column_data };
|
|
87
|
+
let mcols = column_data.columns || [];
|
|
88
|
+
let mcolExts = column_data.columnExtensions || [];
|
|
89
|
+
let rightColumns = column_data.rightColumns || [];
|
|
90
|
+
let leftColumns = column_data.leftColumns || [];
|
|
91
|
+
let editableColumns = column_data.editableColumns || [];
|
|
92
|
+
let customColumns = column_data.customColumns || [];
|
|
93
|
+
|
|
94
|
+
if (!Array.isArray(mcols)) return [];
|
|
95
|
+
//columns given as objects are readonly unless something makes them editable
|
|
96
|
+
const object_columns = new Set<any>();
|
|
97
|
+
/* ------------------------------- fix columns ------------------------------ */
|
|
98
|
+
|
|
99
|
+
mcols
|
|
100
|
+
.map((r) => {
|
|
101
|
+
if (r == null) return null;
|
|
102
|
+
if (typeof r === 'string') return { field: r, header: r };
|
|
103
|
+
if (typeof r === 'object') {
|
|
104
|
+
let final_cl: MakeWriteable<ColumnDefinition> = {
|
|
105
|
+
name: get_col_name(r),
|
|
106
|
+
header: get_col_header(r),
|
|
107
|
+
width: r.width || undefined,
|
|
108
|
+
};
|
|
109
|
+
final_cl = {
|
|
110
|
+
...defaultColumnOptions,
|
|
111
|
+
...r,
|
|
112
|
+
...final_cl,
|
|
113
|
+
};
|
|
114
|
+
object_columns.add(final_cl);
|
|
115
|
+
return final_cl;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
})
|
|
119
|
+
.forEach((r) => {
|
|
120
|
+
if (r != null) final_columns.push(r);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/* ---------------------------- apply extensions ---------------------------- */
|
|
124
|
+
if (mcolExts && Array.isArray(mcolExts))
|
|
125
|
+
for (let index = 0; index < mcolExts.length; index++) {
|
|
126
|
+
const ext = mcolExts[index];
|
|
127
|
+
const ext_cl = get_col_name(ext);
|
|
128
|
+
if (!ext_cl) {
|
|
129
|
+
console.warn('ColumnExtension must have a name');
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const mcol = final_columns.find((s) => get_col_name(s) === ext_cl);
|
|
133
|
+
if (mcol) {
|
|
134
|
+
for (const key in ext) {
|
|
135
|
+
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* ------------------------------- frozen cols ------------------------------ */
|
|
142
|
+
if (Array.isArray(leftColumns)) {
|
|
143
|
+
for (let index = 0; index < leftColumns.length; index++) {
|
|
144
|
+
const r = get_col_name(leftColumns[index]);
|
|
145
|
+
const mcol = final_columns.find((s) => get_col_name(s) === r);
|
|
146
|
+
if (mcol) {
|
|
147
|
+
mcol.locked = 'start';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(rightColumns)) {
|
|
152
|
+
for (let index = 0; index < rightColumns.length; index++) {
|
|
153
|
+
const r = get_col_name(rightColumns[index]);
|
|
154
|
+
const mcol = final_columns.find((s) => get_col_name(s) === r);
|
|
155
|
+
if (mcol) {
|
|
156
|
+
mcol.locked = 'end';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/* -------------------------------- ediatable ------------------------------- */
|
|
161
|
+
if (Array.isArray(editableColumns)) {
|
|
162
|
+
for (let index = 0; index < editableColumns.length; index++) {
|
|
163
|
+
const r = get_col_name(editableColumns[index]);
|
|
164
|
+
const mcol = final_columns.find((s) => get_col_name(s) === r);
|
|
165
|
+
if (mcol) {
|
|
166
|
+
mcol.editable = true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
171
|
+
const col = final_columns[index];
|
|
172
|
+
const coltype = col.type;
|
|
173
|
+
delete col.type;
|
|
174
|
+
if (coltype) {
|
|
175
|
+
switch (coltype) {
|
|
176
|
+
case 'combo':
|
|
177
|
+
case 'select':
|
|
178
|
+
//@ts-ignore
|
|
179
|
+
col.editor = SelectEditor;
|
|
180
|
+
break;
|
|
181
|
+
case 'int':
|
|
182
|
+
case 'number':
|
|
183
|
+
case 'numberic':
|
|
184
|
+
col.type = 'number';
|
|
185
|
+
break;
|
|
186
|
+
case 'truefalse':
|
|
187
|
+
case 'bool':
|
|
188
|
+
case 'boolean':
|
|
189
|
+
//@ts-ignore
|
|
190
|
+
col.editor = BoolEditor;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
//typed columns are editable unless the consumer set editable (a function decides per cell)
|
|
194
|
+
if (col.editable === undefined) col.editable = true;
|
|
195
|
+
}
|
|
196
|
+
if (col.editable === undefined && object_columns.has(col)) col.editable = false;
|
|
197
|
+
//@ts-ignore
|
|
198
|
+
if (!col.editorProps) col.editorProps = {};
|
|
199
|
+
if (col.items) {
|
|
200
|
+
//@ts-ignore
|
|
201
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
202
|
+
//@ts-ignore
|
|
203
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
204
|
+
//@ts-ignore
|
|
205
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
206
|
+
|
|
207
|
+
delete col.items;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* -------------------------------------------------------------------------- */
|
|
212
|
+
if (Array.isArray(customColumns)) {
|
|
213
|
+
for (let index = 0; index < customColumns.length; index++) {
|
|
214
|
+
const r = customColumns[index];
|
|
215
|
+
const rn = get_col_name(r);
|
|
216
|
+
const mcol = final_columns.find((s) => get_col_name(s) === rn);
|
|
217
|
+
if (mcol) {
|
|
218
|
+
//@ts-ignore
|
|
219
|
+
mcol.render = r.render;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* ------------------------------ apply renames ----------------------------- */
|
|
225
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
226
|
+
const col = final_columns[index];
|
|
227
|
+
if (!col.name) {
|
|
228
|
+
col.name = get_col_name(col);
|
|
229
|
+
delete col.field;
|
|
230
|
+
delete col.key;
|
|
231
|
+
delete col.columnName;
|
|
232
|
+
|
|
233
|
+
if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/* -------------------------------------------------------------------------- */
|
|
237
|
+
//console.log(final_columns);
|
|
238
|
+
return final_columns;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* converts select items to an editor dataSource, plain values keep their case as the id
|
|
243
|
+
* @param arr
|
|
244
|
+
* @param idProperty
|
|
245
|
+
* @param valueAsID false uses generated ids instead of the values
|
|
246
|
+
*/
|
|
247
|
+
export function to_datasource(arr: any[], idProperty: string, valueAsID = true) {
|
|
248
|
+
const res: any[] = [];
|
|
249
|
+
let index = 0;
|
|
250
|
+
if (Array.isArray(arr)) {
|
|
251
|
+
arr.map((s: any) => {
|
|
252
|
+
let elem = {};
|
|
253
|
+
if (valueAsID) elem[idProperty] = String(s);
|
|
254
|
+
else elem[idProperty] = '_cid_' + index;
|
|
255
|
+
if (typeof s === 'object') elem = { ...elem, ...s };
|
|
256
|
+
else elem['label'] = s;
|
|
257
|
+
res.push(elem);
|
|
258
|
+
index++;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return res;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Gets name of a column from its column object
|
|
266
|
+
* @param obj
|
|
267
|
+
* @returns
|
|
268
|
+
*/
|
|
269
|
+
export function get_col_name(obj: any): string {
|
|
270
|
+
if (!obj) return '';
|
|
271
|
+
if (typeof obj == 'string') return obj;
|
|
272
|
+
if (typeof obj != 'object') return '';
|
|
273
|
+
return obj.name || obj.field || obj.key || obj.columnName || '';
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Gets header of a column
|
|
277
|
+
* @param obj
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
export function get_col_header(obj: any): string {
|
|
281
|
+
if (!obj) return '';
|
|
282
|
+
if (typeof obj == 'string') return obj;
|
|
283
|
+
if (typeof obj != 'object') return '';
|
|
284
|
+
return obj.header || obj.title || get_col_name(obj);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Gets name of a column from its column object
|
|
288
|
+
* @param obj
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
291
|
+
export function get_row_id(obj: any): any {
|
|
292
|
+
if (typeof obj === 'string') return obj;
|
|
293
|
+
if (typeof obj !== 'object' || !obj) return undefined;
|
|
294
|
+
return obj.__table_id || obj.id || undefined;
|
|
295
|
+
}
|
|
296
|
+
export function set_row_id(obj: any, val: undefined | string): any {
|
|
297
|
+
if (typeof obj != 'object') return false;
|
|
298
|
+
if (val === undefined) delete obj.__table_id;
|
|
299
|
+
else obj.__table_id = val;
|
|
300
|
+
return obj.__table_id;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Gets default activation key for grid plugin
|
|
305
|
+
* THIS KEY IS FOR DEBUGGING PURPOSE ONLY.
|
|
306
|
+
* PROVIDE YOUR OWN KEY
|
|
307
|
+
* @returns
|
|
308
|
+
*/
|
|
309
|
+
export function get_default_key() {
|
|
310
|
+
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
//check if two cache objects are the same
|
|
314
|
+
export function validateCache(current: any, old: any, looseCheck = false) {
|
|
315
|
+
//deep compare skip/limit/filterValue/sortInfo, array order matters (sort priority)
|
|
316
|
+
if (!old || !object_equals(current, old, { strictArrayCheck: true })) return false;
|
|
317
|
+
|
|
318
|
+
if (looseCheck) return true;
|
|
319
|
+
|
|
320
|
+
if (current.ds != old.ds) return false;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* find the real index of the given row data
|
|
326
|
+
* @param view
|
|
327
|
+
*/
|
|
328
|
+
function find_realIndex(view) {
|
|
329
|
+
let current_parent = view;
|
|
330
|
+
|
|
331
|
+
for (let index = 0; index < 3; index++) {
|
|
332
|
+
current_parent = current_parent.parentElement;
|
|
333
|
+
const dataId = current_parent?.getAttribute('data-row-id');
|
|
334
|
+
if (dataId) return dataId;
|
|
335
|
+
}
|
|
336
|
+
return -1;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* find the real index of the given row data
|
|
341
|
+
* sometimes when we scroll the rowData prop becomes invalid
|
|
342
|
+
* but we can manually find the correct data by reading the id from clicked item's Html props
|
|
343
|
+
* @param view
|
|
344
|
+
*/
|
|
345
|
+
export function find_realData(alldata: any[], view, def = undefined) {
|
|
346
|
+
if (!Array.isArray(alldata)) return def;
|
|
347
|
+
const rid = find_realIndex(view);
|
|
348
|
+
if (rid === -1) return def;
|
|
349
|
+
// console.log('dataSource', alldata);
|
|
350
|
+
return alldata.find((s) => get_row_id(s) === rid);
|
|
351
|
+
}
|