react-graph-grid 0.0.0 → 0.0.2
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/README.md +2 -15
- package/package.json +2 -2
- package/src/Dropdown.jsx +1 -1
- package/src/FieldEdit.jsx +374 -0
- package/src/Graph.jsx +34 -5
- package/src/Grid.jsx +13 -5
- package/src/GridDB.jsx +1 -1
- package/src/GridFE.jsx +509 -0
- package/src/GridFL.jsx +11 -1
- package/src/GridGR.jsx +13 -0
- package/src/Overlay.jsx +4 -2
- package/src/Tests/DebugApp.jsx +49 -2
- package/src/Tests/TestData.jsx +86 -683
- package/src/Themes/Images.jsx +1 -1
- package/src/Themes/Translate.jsx +1 -1
- package/src/main.jsx +3 -4
package/src/GridFE.jsx
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
/* eslint-disable no-mixed-operators */
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { GridFLClass } from './GridFL';
|
|
4
|
+
import { FieldEdit } from './FieldEdit';
|
|
5
|
+
import { Images } from './Themes/Images';
|
|
6
|
+
import { Modal } from './Modal';
|
|
7
|
+
// ==================================================================================================================================================================
|
|
8
|
+
export function GridFE(props) {
|
|
9
|
+
let grid = null;
|
|
10
|
+
|
|
11
|
+
const [gridState, setState] = useState({ grid: grid, ind: 0 });
|
|
12
|
+
|
|
13
|
+
grid = gridState.grid;
|
|
14
|
+
let needGetRows = false;
|
|
15
|
+
if (!grid || grid.uid !== props.uid && props.uid != null) {
|
|
16
|
+
grid = null;
|
|
17
|
+
if (props.findGrid) {
|
|
18
|
+
grid = props.findGrid(props);
|
|
19
|
+
}
|
|
20
|
+
grid = grid || new GridFEClass(props);
|
|
21
|
+
needGetRows = !props.noAutoRefresh && !grid.hasVisibleParentGrids();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (props.init) {
|
|
25
|
+
props.init(grid);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
grid.refreshState = function () {
|
|
29
|
+
setState({ grid: grid, ind: grid.stateind++ });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
grid.setupEvents();
|
|
34
|
+
|
|
35
|
+
if (needGetRows && (grid.rows.length <= 0 || grid.columns.length <= 0) || grid._forceRefresh) {
|
|
36
|
+
|
|
37
|
+
grid._forceRefresh = false;
|
|
38
|
+
|
|
39
|
+
grid._waitingRows = true;
|
|
40
|
+
grid.getRows({ filters: grid.collectFilters(), grid: grid }).then(
|
|
41
|
+
rows => {
|
|
42
|
+
grid.rows = rows;
|
|
43
|
+
grid.afterGetRows();
|
|
44
|
+
grid.refreshState();
|
|
45
|
+
}
|
|
46
|
+
).finally(() => {
|
|
47
|
+
grid._waitingRows = false;
|
|
48
|
+
grid.refreshState();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (grid.columns.length <= 0 && grid.getColumns) {
|
|
52
|
+
grid.prepareColumns().then(() => grid.refreshState());;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return () => {
|
|
56
|
+
grid.clearEvents();
|
|
57
|
+
}
|
|
58
|
+
}, [grid, needGetRows])
|
|
59
|
+
|
|
60
|
+
return (grid.render());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ==================================================================================================================================================================
|
|
64
|
+
export class GridFEClass extends GridFLClass {
|
|
65
|
+
|
|
66
|
+
constructor(props) {
|
|
67
|
+
super(props);
|
|
68
|
+
|
|
69
|
+
const grid = this;
|
|
70
|
+
|
|
71
|
+
grid.allowEditGrid = props.allowEditGrid;
|
|
72
|
+
|
|
73
|
+
//grid.changedRow = {};
|
|
74
|
+
|
|
75
|
+
grid.closeSelfWnd = grid.closeSelfWnd || (() => { });
|
|
76
|
+
|
|
77
|
+
grid.onSelectValue = props.onSelectValue || (() => { });
|
|
78
|
+
|
|
79
|
+
const shift = (grid.level + 1) * 20;
|
|
80
|
+
grid.popupPos = { x: 100 + shift, y: 100 + shift, w: 800, h: 600 };
|
|
81
|
+
|
|
82
|
+
grid.addToolbarButtons();
|
|
83
|
+
}
|
|
84
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
85
|
+
render() {
|
|
86
|
+
const grid = this;
|
|
87
|
+
return (
|
|
88
|
+
<>
|
|
89
|
+
{super.render()}
|
|
90
|
+
{grid.renderPopup()}
|
|
91
|
+
</>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
95
|
+
isVisible() {
|
|
96
|
+
return this.visible;
|
|
97
|
+
}
|
|
98
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
99
|
+
renderPopup() {
|
|
100
|
+
const grid = this;
|
|
101
|
+
return (
|
|
102
|
+
grid.popupIsShowing ?
|
|
103
|
+
<Modal
|
|
104
|
+
title={grid.popupTitle}
|
|
105
|
+
level={grid.level + 1}
|
|
106
|
+
renderContent={(wnd) => { return grid.renderPopupContent(wnd) }}
|
|
107
|
+
dimensionsByContent={grid.popupDimensionsByContent}
|
|
108
|
+
pos={grid.popupPos}
|
|
109
|
+
closeWhenEscape={grid.popupCloseWhenEscape}
|
|
110
|
+
onClose={(e) => {
|
|
111
|
+
grid.onClosePopup(e);
|
|
112
|
+
grid.refreshState();
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
</Modal>
|
|
116
|
+
:
|
|
117
|
+
<></>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
121
|
+
onClosePopup() {
|
|
122
|
+
const grid = this;
|
|
123
|
+
grid.popupIsShowing = false;
|
|
124
|
+
grid.popupCloseWhenEscape = false;
|
|
125
|
+
grid.popupTitle = '';
|
|
126
|
+
}
|
|
127
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
128
|
+
renderPopupContent() {
|
|
129
|
+
return <></>;
|
|
130
|
+
}
|
|
131
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
132
|
+
renderCell(grid, col, row, selected) {
|
|
133
|
+
if (!grid.allowEditGrid && !col.allowVerticalResize || !selected || grid.isDisabled()) return super.renderCell(grid, col, row);
|
|
134
|
+
|
|
135
|
+
row = !grid.isEditing() || !grid.changedRow ? row : grid.changedRow;
|
|
136
|
+
|
|
137
|
+
return <FieldEdit
|
|
138
|
+
keyPref={grid.id + '_' + row[grid.keyField]}
|
|
139
|
+
column={col}
|
|
140
|
+
value={col.type === 'lookup' ? row[col.keyField] : row[col.name]}
|
|
141
|
+
text={row[col.name]}
|
|
142
|
+
findFieldEdit={() => { return col._fieldEditObj; }}
|
|
143
|
+
selectH={'1.4em'}
|
|
144
|
+
level={grid.level}
|
|
145
|
+
init={
|
|
146
|
+
(fe) => {
|
|
147
|
+
if (grid.isEditing() && !grid.changedRow) {
|
|
148
|
+
grid.changedRow = {};
|
|
149
|
+
Object.assign(grid.changedRow, grid.selectedRow());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fe.ownerGrid = grid;
|
|
153
|
+
|
|
154
|
+
const lrow = !grid.isEditing() ? grid.selectedRow() : grid.changedRow;
|
|
155
|
+
|
|
156
|
+
col._fieldEditObj = fe;
|
|
157
|
+
fe.value = col.type === 'lookup' ? lrow[col.keyField] : lrow[col.name];
|
|
158
|
+
fe.text = lrow[col.name];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
onChange={(e) => {
|
|
162
|
+
if (!grid.changedRow) {
|
|
163
|
+
grid.changedRow = {};
|
|
164
|
+
Object.assign(grid.changedRow, grid.selectedRow());
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (col.type === 'lookup') {
|
|
168
|
+
grid.changedRow[col.keyField] = e.value;
|
|
169
|
+
grid.changedRow[col.name] = e.text;
|
|
170
|
+
if (!grid.isEditing()) {
|
|
171
|
+
grid.setEditing(true);
|
|
172
|
+
grid.refreshState();
|
|
173
|
+
}
|
|
174
|
+
e.fe.refreshState();
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
grid.changedRow[col.name] = e.value;
|
|
178
|
+
if (!grid.isEditing()) {
|
|
179
|
+
grid.setEditing(true);
|
|
180
|
+
grid.refreshState();
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
e.fe.refreshState();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
</FieldEdit>
|
|
189
|
+
}
|
|
190
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
191
|
+
addToolbarButtons() {
|
|
192
|
+
const grid = this;
|
|
193
|
+
|
|
194
|
+
//node.buttons.push({
|
|
195
|
+
// id: node.buttons.length,
|
|
196
|
+
// name: 'edit',
|
|
197
|
+
// title: node.translate('Start edit'),
|
|
198
|
+
// label: node.images.edit ? '' : node.translate('Start edit'),
|
|
199
|
+
// click: (e) => node.startEdit(e),
|
|
200
|
+
// img: node.images.edit
|
|
201
|
+
//});
|
|
202
|
+
|
|
203
|
+
grid.buttons.push({
|
|
204
|
+
id: grid.buttons.length,
|
|
205
|
+
name: 'commit',
|
|
206
|
+
title: grid.translate('Commit changes'),
|
|
207
|
+
label: grid.translate('Commit'),
|
|
208
|
+
img: Images.images.commit,
|
|
209
|
+
click: (e) => grid.commitChanges(e),
|
|
210
|
+
getDisabled: (e) => grid.commitChangesDisabled(e),
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
grid.buttons.push({
|
|
214
|
+
id: grid.buttons.length,
|
|
215
|
+
name: 'rollback',
|
|
216
|
+
title: grid.translate('Rollback changes'),
|
|
217
|
+
label: grid.translate('Rollback'),
|
|
218
|
+
img: Images.images.rollback,
|
|
219
|
+
click: (e) => grid.rollbackChanges(e),
|
|
220
|
+
getDisabled: (e) => grid.rollbackChangesDisabled(e),
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
grid.buttons.push({
|
|
224
|
+
id: grid.buttons.length,
|
|
225
|
+
name: 'add',
|
|
226
|
+
title: grid.translate('Add new record'),
|
|
227
|
+
label: grid.translate('Add'),
|
|
228
|
+
img: Images.images.addRecord,
|
|
229
|
+
click: (e) => grid.addRecord(e),
|
|
230
|
+
getDisabled: (e) => grid.addRecordDisabled(e),
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
grid.buttons.push({
|
|
234
|
+
id: grid.buttons.length,
|
|
235
|
+
name: 'copy',
|
|
236
|
+
title: grid.translate('Copy record'),
|
|
237
|
+
label: grid.translate('Copy'),
|
|
238
|
+
img: Images.images.copyRecord,
|
|
239
|
+
click: (e) => grid.copyRecord(e),
|
|
240
|
+
getDisabled: (e) => grid.copyRecordDisabled(e),
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
grid.buttons.push({
|
|
244
|
+
id: grid.buttons.length,
|
|
245
|
+
name: 'delete',
|
|
246
|
+
title: grid.translate('Delete record'),
|
|
247
|
+
label: grid.translate('Delete'),
|
|
248
|
+
img: Images.images.deleteRecord,
|
|
249
|
+
click: (e) => grid.deleteRecord(e),
|
|
250
|
+
getDisabled: (e) => grid.deleteRecordDisabled(e),
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
grid.buttons.push({
|
|
254
|
+
id: grid.buttons.length,
|
|
255
|
+
name: 'view',
|
|
256
|
+
title: grid.translate('View record'),
|
|
257
|
+
label: grid.translate('View'),
|
|
258
|
+
img: Images.images.viewRecord,
|
|
259
|
+
click: (e) => grid.viewRecord(e),
|
|
260
|
+
getDisabled: (e) => grid.viewRecordDisabled(e),
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
grid.buttons.push({
|
|
264
|
+
id: grid.buttons.length,
|
|
265
|
+
name: 'selectValue',
|
|
266
|
+
title: grid.translate('Select value'),
|
|
267
|
+
label: grid.translate('Select'),
|
|
268
|
+
click: (e) => grid.selectRecord(e),
|
|
269
|
+
img: Images.images.selectFilterValue,
|
|
270
|
+
getDisabled: (e) => grid.selectRecordDisabled(e),
|
|
271
|
+
getVisible: () => { return grid.isSelecting },
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
grid.buttons.push({
|
|
275
|
+
id: grid.buttons.length,
|
|
276
|
+
name: 'exit',
|
|
277
|
+
title: grid.translate('Exit'),
|
|
278
|
+
label: grid.translate('Exit'),
|
|
279
|
+
click: (e) => grid.closeSelfWnd(e),
|
|
280
|
+
img: Images.images.exit,
|
|
281
|
+
getDisabled: (e) => grid.exitDisabled(e),
|
|
282
|
+
getVisible: () => { return grid.isSelecting },
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
grid._buttonsDict = {};
|
|
286
|
+
for (let btn of grid.buttons) {
|
|
287
|
+
grid._buttonsDict[btn.name] = btn;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
291
|
+
selectRecord(e) {
|
|
292
|
+
const grid = this;
|
|
293
|
+
const row = grid.selectedRow();
|
|
294
|
+
delete grid._selectedRows;
|
|
295
|
+
|
|
296
|
+
if (!grid.multi || !grid.pocketOpened) {
|
|
297
|
+
e.value = row[grid.keyField];
|
|
298
|
+
e.text = row[grid.nameField];
|
|
299
|
+
e.values = [{ value: e.value, label: e.text }];
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
e.multi = true;
|
|
303
|
+
if (Object.keys(grid._selectedRowsDict).length === 0) {
|
|
304
|
+
grid._selectedRowsDict[row[grid.keyField]] = row;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const texts = [];
|
|
308
|
+
e.value = grid.selectedValue();
|
|
309
|
+
e.values = grid.selectedValues(texts);
|
|
310
|
+
e.text = texts.join(', ');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
grid.onSelectValue(e);
|
|
314
|
+
}
|
|
315
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
316
|
+
onRowDblClick(e, row) {
|
|
317
|
+
const grid = this;
|
|
318
|
+
super.onRowDblClick(e, row);
|
|
319
|
+
|
|
320
|
+
if (grid.isSelecting && !grid.multi && grid.onSelectValue) {
|
|
321
|
+
const row = grid.selectedRow();
|
|
322
|
+
e.value = row[grid.keyField];
|
|
323
|
+
e.text = row[grid.nameField];
|
|
324
|
+
grid.onSelectValue(e);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
328
|
+
commitChanges(e) {
|
|
329
|
+
const grid = this;
|
|
330
|
+
|
|
331
|
+
const row = grid.selectedRow();
|
|
332
|
+
|
|
333
|
+
grid.saveRow({ row: row, changedRow: grid.changedRow }).then(
|
|
334
|
+
() => {
|
|
335
|
+
grid.setEditing(false);
|
|
336
|
+
Object.assign(row, grid.changedRow);
|
|
337
|
+
delete grid.changedRow;
|
|
338
|
+
grid.refreshState();
|
|
339
|
+
}
|
|
340
|
+
).catch((message) => {
|
|
341
|
+
Object.assign(grid.changedRow, row);
|
|
342
|
+
grid.refreshState();
|
|
343
|
+
alert(message || 'Error!');
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
347
|
+
commitChangesDisabled(e) {
|
|
348
|
+
const grid = this;
|
|
349
|
+
return grid._waitingRows || !grid.isEditing() || grid.isDisabled();
|
|
350
|
+
}
|
|
351
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
352
|
+
rollbackChanges(e) {
|
|
353
|
+
const grid = this;
|
|
354
|
+
|
|
355
|
+
delete grid.changedRow;
|
|
356
|
+
grid.setEditing(false);
|
|
357
|
+
grid.refreshState();
|
|
358
|
+
}
|
|
359
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
360
|
+
rollbackChangesDisabled(e) {
|
|
361
|
+
const grid = this;
|
|
362
|
+
return grid._waitingRows || !grid.isEditing() || grid.isDisabled();
|
|
363
|
+
}
|
|
364
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
365
|
+
addRecord(e) {
|
|
366
|
+
const grid = this;
|
|
367
|
+
|
|
368
|
+
grid.getNewRow().then((newRow) => {
|
|
369
|
+
grid.refreshState();
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
373
|
+
addRecordDisabled(e) {
|
|
374
|
+
const grid = this;
|
|
375
|
+
return grid._waitingRows || !grid.allowAdd || grid.isEditing() || grid.isDisabled();
|
|
376
|
+
}
|
|
377
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
378
|
+
copyRecord(e) {
|
|
379
|
+
const grid = this;
|
|
380
|
+
|
|
381
|
+
let newRow;
|
|
382
|
+
Object.assign(newRow, grid.selectedRow());
|
|
383
|
+
|
|
384
|
+
grid.refreshState();
|
|
385
|
+
}
|
|
386
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
387
|
+
copyRecordDisabled(e) {
|
|
388
|
+
const grid = this;
|
|
389
|
+
return grid._waitingRows || !grid.allowCopy || grid.isEditing() || grid.isDisabled() || grid.selectedRowIndex == null || grid.selectedRowIndex < 0 || !grid.rows || grid.rows.length <= 0;
|
|
390
|
+
}
|
|
391
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
392
|
+
deleteRecord(e) {
|
|
393
|
+
const grid = this;
|
|
394
|
+
|
|
395
|
+
if (window.confirm(grid.translate('Delete record') + '?')) {
|
|
396
|
+
grid.deleteRow(e).then(() => grid.refresh());
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
400
|
+
deleteRecordDisabled(e) {
|
|
401
|
+
const grid = this;
|
|
402
|
+
return grid._waitingRows || !grid.allowDelete || grid.isEditing() || grid.isDisabled() || grid.selectedRowIndex == null || grid.selectedRowIndex < 0 || !grid.rows || grid.rows.length <= 0;
|
|
403
|
+
}
|
|
404
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
405
|
+
viewRecord(e) {
|
|
406
|
+
const grid = this;
|
|
407
|
+
|
|
408
|
+
let cardRow = grid.selectedRow();
|
|
409
|
+
|
|
410
|
+
grid.refreshState();
|
|
411
|
+
}
|
|
412
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
413
|
+
viewRecordDisabled(e) {
|
|
414
|
+
const grid = this;
|
|
415
|
+
return grid._waitingRows || !grid.allowView || grid.isEditing() || grid.isDisabled() || grid.selectedRowIndex == null || grid.selectedRowIndex < 0 || !grid.rows || grid.rows.length <= 0;
|
|
416
|
+
}
|
|
417
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
418
|
+
selectRecordDisabled(e) {
|
|
419
|
+
const grid = this;
|
|
420
|
+
return grid._waitingRows || !grid.isSelecting || grid.isEditing() || grid.isDisabled() || grid.selectedRowIndex == null || grid.selectedRowIndex < 0 || !grid.rows || grid.rows.length <= 0;
|
|
421
|
+
}
|
|
422
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
423
|
+
exitDisabled(e) {
|
|
424
|
+
const grid = this;
|
|
425
|
+
return grid._waitingRows || !grid.isSelecting || grid.isEditing() || grid.isDisabled();
|
|
426
|
+
}
|
|
427
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
428
|
+
onSelectedRowChanged(e) {
|
|
429
|
+
const grid = this;
|
|
430
|
+
super.onSelectedRowChanged(e);
|
|
431
|
+
|
|
432
|
+
if (grid.allowEditGrid && grid.refreshState) {
|
|
433
|
+
grid.refreshState();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
437
|
+
getSelectedRowIndex() {
|
|
438
|
+
const grid = this;
|
|
439
|
+
if (grid.value == null || grid.value === '') return;
|
|
440
|
+
|
|
441
|
+
let i = 0;
|
|
442
|
+
for (let row of grid.rows) {
|
|
443
|
+
if (row[grid.keyField] === grid.value) {
|
|
444
|
+
grid.selectedRowIndex = i;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
i++;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
451
|
+
getGridMaxHeight() {
|
|
452
|
+
const grid = this;
|
|
453
|
+
return grid.frozenHeader ? grid.children && grid.children.length > 0 || grid.parents && grid.parents.length > 0 ? '40vh' : '80vh' : '';
|
|
454
|
+
}
|
|
455
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
456
|
+
async canLeaveRow(rowIndex) {
|
|
457
|
+
const grid = this;
|
|
458
|
+
let res;
|
|
459
|
+
|
|
460
|
+
return (!grid.allowEditGrid || !grid.isEditing()) && !grid.isDisabled();
|
|
461
|
+
|
|
462
|
+
const row = grid.rows[rowIndex];
|
|
463
|
+
await grid.saveRow({ row: row, changedRow: grid.changedRow }).then(
|
|
464
|
+
() => {
|
|
465
|
+
grid.setEditing(false);
|
|
466
|
+
Object.assign(row, grid.changedRow);
|
|
467
|
+
delete grid.changedRow;
|
|
468
|
+
grid.refreshState();
|
|
469
|
+
res = true;
|
|
470
|
+
}
|
|
471
|
+
).catch((message) => {
|
|
472
|
+
Object.assign(grid.changedRow, row);
|
|
473
|
+
grid.refreshState();
|
|
474
|
+
res = false;
|
|
475
|
+
alert(message || 'Error!');
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
return res;
|
|
479
|
+
}
|
|
480
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
481
|
+
keyCellAdd(selected) {
|
|
482
|
+
const grid = this;
|
|
483
|
+
return selected ? '1' : grid.stateind;
|
|
484
|
+
}
|
|
485
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
486
|
+
isRowChanged(row) {
|
|
487
|
+
const grid = this;
|
|
488
|
+
if (!grid.changedRow) return false;
|
|
489
|
+
|
|
490
|
+
let res = false;
|
|
491
|
+
for (let col in grid.changedRow) {
|
|
492
|
+
if (grid.changedRow[col] !== row[col]) return true;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return res;
|
|
496
|
+
}
|
|
497
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
498
|
+
saveRow(e) {
|
|
499
|
+
const grid = this;
|
|
500
|
+
|
|
501
|
+
if (!grid.isRowChanged(e.row)) return new Promise(function (resolve) { resolve(true); });
|
|
502
|
+
|
|
503
|
+
return new Promise(function (resolve, reject) {
|
|
504
|
+
e.row = e.changedRow;
|
|
505
|
+
resolve(true);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
509
|
+
}
|
package/src/GridFL.jsx
CHANGED
|
@@ -17,7 +17,7 @@ export function GridFL(props) {
|
|
|
17
17
|
grid = props.findGrid(props);
|
|
18
18
|
}
|
|
19
19
|
grid = grid || new GridFLClass(props);
|
|
20
|
-
needGetRows = !props.noAutoRefresh && !
|
|
20
|
+
needGetRows = !props.noAutoRefresh && !grid.hasVisibleParentGrids();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (props.init) {
|
|
@@ -139,6 +139,7 @@ export class GridFLClass extends GridDBClass {
|
|
|
139
139
|
disabled={isDisabled ? 'disabled' : ''}
|
|
140
140
|
onBlur={(e) => { grid.onColumnFocusLost(col, col.filter, e); }}
|
|
141
141
|
autoComplete="off"
|
|
142
|
+
autocomplete="off"
|
|
142
143
|
>
|
|
143
144
|
</input>
|
|
144
145
|
{
|
|
@@ -240,6 +241,8 @@ export class GridFLClass extends GridDBClass {
|
|
|
240
241
|
showAutocomplete(e) {
|
|
241
242
|
const grid = this;
|
|
242
243
|
|
|
244
|
+
if (grid._waitingRows) return;
|
|
245
|
+
|
|
243
246
|
if (grid._autocompleteRect) {
|
|
244
247
|
grid._autocompleteDropdown.opt.parentRect = grid._autocompleteRect;
|
|
245
248
|
}
|
|
@@ -312,6 +315,8 @@ export class GridFLClass extends GridDBClass {
|
|
|
312
315
|
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
313
316
|
onColumnFocusLost(column, filter, e) {
|
|
314
317
|
const grid = this;
|
|
318
|
+
grid._waitingRows = true;
|
|
319
|
+
|
|
315
320
|
if (grid._inputingColumn !== column) {
|
|
316
321
|
//console.log('onColumnFocusLost: grid._inputingColumn !== column');
|
|
317
322
|
delete grid._inputingColumn;
|
|
@@ -328,12 +333,17 @@ export class GridFLClass extends GridDBClass {
|
|
|
328
333
|
grid.selectedRowIndex = 0;
|
|
329
334
|
grid.refresh();
|
|
330
335
|
}
|
|
336
|
+
else {
|
|
337
|
+
grid._waitingRows = false;
|
|
338
|
+
}
|
|
331
339
|
}, 150);
|
|
332
340
|
}
|
|
333
341
|
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
334
342
|
onColumnFilterClick(col, e) {
|
|
335
343
|
const grid = this;
|
|
336
344
|
|
|
345
|
+
if (grid._waitingRows) return;
|
|
346
|
+
|
|
337
347
|
grid._inputingColumn = col;
|
|
338
348
|
e.target.focus();
|
|
339
349
|
setTimeout(() => {
|
package/src/GridGR.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { GridClass } from './Grid';
|
|
3
3
|
import { GraphClass } from './Graph';
|
|
4
|
+
import { NodeStatus } from './Base';
|
|
4
5
|
// ==================================================================================================================================================================
|
|
5
6
|
export function GridGR(props) {
|
|
6
7
|
let grid = null;
|
|
@@ -307,4 +308,16 @@ export class GridGRClass extends GridClass {
|
|
|
307
308
|
});
|
|
308
309
|
}
|
|
309
310
|
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
311
|
+
hasVisibleParentGrids() {
|
|
312
|
+
const grid = this;
|
|
313
|
+
if (!grid.graph) return false;
|
|
314
|
+
|
|
315
|
+
for (let puid of grid.parents) {
|
|
316
|
+
let pnode = grid.graph.nodesDict[puid];
|
|
317
|
+
if (pnode.visible !== false && pnode.status === NodeStatus.grid) return true;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
310
323
|
}
|
package/src/Overlay.jsx
CHANGED
|
@@ -6,9 +6,11 @@ export function Overlay(props) {
|
|
|
6
6
|
|
|
7
7
|
const [ovlState, setState] = useState({ ovl: ovl, ind: 0 });
|
|
8
8
|
|
|
9
|
-
if (ovlState.ovl
|
|
9
|
+
if (ovlState.ovl) {
|
|
10
10
|
ovl = ovlState.ovl;
|
|
11
|
-
ovl.closing
|
|
11
|
+
if (ovlState.ovl.closing) {
|
|
12
|
+
ovl.closing = false;
|
|
13
|
+
}
|
|
12
14
|
}
|
|
13
15
|
else {
|
|
14
16
|
ovl = new OverlayClass(props);
|
package/src/Tests/DebugApp.jsx
CHANGED
|
@@ -7,6 +7,8 @@ import { Grid } from '../Grid';
|
|
|
7
7
|
import { GridGR } from '../GridGR';
|
|
8
8
|
import { GridDB } from '../GridDB';
|
|
9
9
|
import { GridFL } from '../GridFL';
|
|
10
|
+
import { GridFE } from '../GridFE';
|
|
11
|
+
import { FieldEdit } from '../FieldEdit';
|
|
10
12
|
//import { GridINU } from '../GridINU';
|
|
11
13
|
//import { GraphComponent } from '../GraphComponent';
|
|
12
14
|
|
|
@@ -225,6 +227,49 @@ function DebugApp() {
|
|
|
225
227
|
</div>
|
|
226
228
|
</>
|
|
227
229
|
);
|
|
230
|
+
case 8:
|
|
231
|
+
return (
|
|
232
|
+
<>
|
|
233
|
+
<Modal uid="m01" isModal={true} closeWhenEscape={true}
|
|
234
|
+
renderContent={() => {
|
|
235
|
+
return (
|
|
236
|
+
<div className="div-with-grid">
|
|
237
|
+
<span>Persona</span>
|
|
238
|
+
<FieldEdit
|
|
239
|
+
column={{
|
|
240
|
+
id: 1,
|
|
241
|
+
name: 'Persona',
|
|
242
|
+
getRows: GetFamily,
|
|
243
|
+
refKeyField: 'Id',
|
|
244
|
+
refNameField: 'Name',
|
|
245
|
+
type: 'lookup',
|
|
246
|
+
}}
|
|
247
|
+
>
|
|
248
|
+
</FieldEdit>
|
|
249
|
+
<br></br>
|
|
250
|
+
<span>Age</span>
|
|
251
|
+
<FieldEdit
|
|
252
|
+
column={{
|
|
253
|
+
id: 2,
|
|
254
|
+
name: 'Age',
|
|
255
|
+
}}
|
|
256
|
+
>
|
|
257
|
+
</FieldEdit>
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
}}
|
|
261
|
+
pos={{ x: 100, y: 100, w: 400, h: 200 }} title='Field Edit'>
|
|
262
|
+
</Modal>
|
|
263
|
+
</>
|
|
264
|
+
)
|
|
265
|
+
case 9:
|
|
266
|
+
return (
|
|
267
|
+
<>
|
|
268
|
+
<div className="div-with-grid">
|
|
269
|
+
<GridFE getRows={GetFamily} getColumns={GetFamilyColumns} allowEditGrid={true}></GridFE>
|
|
270
|
+
</div>
|
|
271
|
+
</>
|
|
272
|
+
);
|
|
228
273
|
case 11:
|
|
229
274
|
return (
|
|
230
275
|
<>
|
|
@@ -243,14 +288,16 @@ function DebugApp() {
|
|
|
243
288
|
setState({ menuItem: e.target.selectedIndex });
|
|
244
289
|
}}>
|
|
245
290
|
<option>0. None</option>
|
|
246
|
-
<option>1.
|
|
291
|
+
<option>1. React Grid</option>
|
|
247
292
|
<option>2. Overlay</option>
|
|
248
293
|
<option>3. Modal</option>
|
|
249
294
|
<option>4. Dropdown</option>
|
|
250
295
|
<option>5. Two Grids</option>
|
|
251
296
|
<option>6. GridDB</option>
|
|
252
297
|
<option>7. GridFL</option>
|
|
253
|
-
<option>
|
|
298
|
+
<option>8. Field Edit</option>
|
|
299
|
+
<option>9. GridFE</option>
|
|
300
|
+
<option>10. TEST</option>
|
|
254
301
|
</select>
|
|
255
302
|
<div className="div-on-menu">
|
|
256
303
|
{getTestApp()}
|