@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.
@@ -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
- const defaultColumnOptions: ColumnDefinition = {
15
- draggable: false,
16
- lockable: false,
17
- editable: 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
- /* ------------------------------- fix columns ------------------------------ */
96
-
97
- mcols
98
- .map((r) => {
99
- if (r == null) return null;
100
- if (typeof r === 'string') return { field: r, header: r };
101
- if (typeof r === 'object') {
102
- let final_cl: MakeWriteable<ColumnDefinition> = {
103
- name: get_col_name(r),
104
- header: get_col_header(r),
105
- width: r.width || undefined,
106
- };
107
- final_cl = {
108
- ...defaultColumnOptions,
109
- ...r,
110
- ...final_cl,
111
- };
112
- return final_cl;
113
- }
114
- return null;
115
- })
116
- .forEach((r) => {
117
- if (r != null) final_columns.push(r);
118
- });
119
-
120
- /* ---------------------------- apply extensions ---------------------------- */
121
- if (mcolExts && Array.isArray(mcolExts))
122
- for (let index = 0; index < mcolExts.length; index++) {
123
- const ext = mcolExts[index];
124
- const ext_cl = get_col_name(ext);
125
- if (!ext_cl) {
126
- console.warn('ColumnExtension must have a name');
127
- continue;
128
- }
129
- const mcol = final_columns.find((s) => get_col_name(s) === ext_cl);
130
- if (mcol) {
131
- for (const key in ext) {
132
- if (!mcol[key] && key != 'name') mcol[key] = ext[key];
133
- }
134
- }
135
- // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
136
- }
137
-
138
- /* ------------------------------- frozen cols ------------------------------ */
139
- if (Array.isArray(leftColumns)) {
140
- for (let index = 0; index < leftColumns.length; index++) {
141
- const r = get_col_name(leftColumns[index]);
142
- const mcol = final_columns.find((s) => get_col_name(s) === r);
143
- if (mcol) {
144
- mcol.locked = 'start';
145
- }
146
- }
147
- }
148
- if (Array.isArray(rightColumns)) {
149
- for (let index = 0; index < rightColumns.length; index++) {
150
- const r = get_col_name(rightColumns[index]);
151
- const mcol = final_columns.find((s) => get_col_name(s) === r);
152
- if (mcol) {
153
- mcol.locked = 'end';
154
- }
155
- }
156
- }
157
- /* -------------------------------- ediatable ------------------------------- */
158
- if (Array.isArray(editableColumns)) {
159
- for (let index = 0; index < editableColumns.length; index++) {
160
- const r = get_col_name(editableColumns[index]);
161
- const mcol = final_columns.find((s) => get_col_name(s) === r);
162
- if (mcol) {
163
- mcol.editable = true;
164
- }
165
- }
166
- }
167
- for (let index = 0; index < final_columns.length; index++) {
168
- const col = final_columns[index];
169
- const coltype = col.type;
170
- delete col.type;
171
- if (coltype) {
172
- switch (coltype) {
173
- case 'combo':
174
- case 'select':
175
- //@ts-ignore
176
- col.editor = SelectEditor;
177
- break;
178
- case 'int':
179
- case 'number':
180
- case 'numberic':
181
- col.type = 'number';
182
- break;
183
- case 'truefalse':
184
- case 'bool':
185
- case 'boolean':
186
- //@ts-ignore
187
- col.editor = BoolEditor;
188
- break;
189
- }
190
- if (col.editable != false) col.editable = true;
191
- }
192
- //@ts-ignore
193
- if (!col.editorProps) col.editorProps = {};
194
- if (col.items) {
195
- //@ts-ignore
196
- if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
197
- //@ts-ignore
198
- if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
199
- //@ts-ignore
200
- col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
201
-
202
- delete col.items;
203
- }
204
- }
205
-
206
- /* -------------------------------------------------------------------------- */
207
- if (Array.isArray(customColumns)) {
208
- for (let index = 0; index < customColumns.length; index++) {
209
- const r = customColumns[index];
210
- const rn = get_col_name(r);
211
- const mcol = final_columns.find((s) => get_col_name(s) === rn);
212
- if (mcol) {
213
- //@ts-ignore
214
- mcol.render = r.render;
215
- }
216
- }
217
- }
218
-
219
- /* ------------------------------ apply renames ----------------------------- */
220
- for (let index = 0; index < final_columns.length; index++) {
221
- const col = final_columns[index];
222
- if (!col.name) {
223
- col.name = get_col_name(col);
224
- delete col.field;
225
- delete col.key;
226
- delete col.columnName;
227
-
228
- if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
229
- }
230
- }
231
- /* -------------------------------------------------------------------------- */
232
- //console.log(final_columns);
233
- return final_columns;
234
- }
235
-
236
- export function to_datasource(arr: any[], idProperty: string, valueAsID = true) {
237
- const res: any[] = [];
238
- let index = 0;
239
- if (Array.isArray(arr)) {
240
- arr.map((s: any) => {
241
- let elem = {};
242
- if (valueAsID) elem[idProperty] = String(s).toLowerCase();
243
- else elem[idProperty] = '_cid_' + index;
244
- if (typeof s === 'object') elem = { ...elem, ...s };
245
- else elem['label'] = s;
246
- res.push(elem);
247
- index++;
248
- });
249
- }
250
-
251
- return res;
252
- }
253
- /**
254
- * Gets name of a column from its column object
255
- * @param obj
256
- * @returns
257
- */
258
- export function get_col_name(obj: any): string {
259
- if (!obj) return '';
260
- if (typeof obj == 'string') return obj;
261
- if (typeof obj != 'object') return '';
262
- return obj.name || obj.field || obj.key || obj.columnName || '';
263
- }
264
- /**
265
- * Gets header of a column
266
- * @param obj
267
- * @returns
268
- */
269
- export function get_col_header(obj: any): string {
270
- if (!obj) return '';
271
- if (typeof obj == 'string') return obj;
272
- if (typeof obj != 'object') return '';
273
- return obj.header || obj.title || get_col_name(obj);
274
- }
275
- /**
276
- * Gets name of a column from its column object
277
- * @param obj
278
- * @returns
279
- */
280
- export function get_row_id(obj: any): any {
281
- if (typeof obj === 'string') return obj;
282
- if (typeof obj !== 'object' || !obj) return undefined;
283
- return obj.__table_id || obj.id || undefined;
284
- }
285
- export function set_row_id(obj: any, val: undefined | string): any {
286
- if (typeof obj != 'object') return false;
287
- if (val === undefined) delete obj.__table_id;
288
- else obj.__table_id = val;
289
- return obj.__table_id;
290
- }
291
-
292
- /**
293
- * Gets default activation key for grid plugin
294
- * THIS KEY IS FOR DEBUGGING PURPOSE ONLY.
295
- * PROVIDE YOUR OWN KEY
296
- * @returns
297
- */
298
- export function get_default_key() {
299
- return 'ExpiryDate=2999-01-01,Z=1040577552';
300
- }
301
-
302
- //check if two cache objects are the same
303
- export function validateCache(current: any, old: any, looseCheck = false) {
304
- //deep compare skip/limit/filterValue/sortInfo, array order matters (sort priority)
305
- if (!old || !object_equals(current, old, { strictArrayCheck: true })) return false;
306
-
307
- if (looseCheck) return true;
308
-
309
- if (current.ds != old.ds) return false;
310
- return true;
311
- }
312
-
313
- /**
314
- * find the real index of the given row data
315
- * @param view
316
- */
317
- function find_realIndex(view) {
318
- let current_parent = view;
319
-
320
- for (let index = 0; index < 3; index++) {
321
- current_parent = current_parent.parentElement;
322
- const dataId = current_parent?.getAttribute('data-row-id');
323
- if (dataId) return dataId;
324
- }
325
- return -1;
326
- }
327
-
328
- /**
329
- * find the real index of the given row data
330
- * sometimes when we scroll the rowData prop becomes invalid
331
- * but we can manually find the correct data by reading the id from clicked item's Html props
332
- * @param view
333
- */
334
- export function find_realData(alldata: any[], view, def = undefined) {
335
- if (!Array.isArray(alldata)) return def;
336
- const rid = find_realIndex(view);
337
- if (rid === -1) return def;
338
- // console.log('dataSource', alldata);
339
- return alldata.find((s) => get_row_id(s) === rid);
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
+ }