@apia/execution 5.0.3 → 5.2.0

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.
Files changed (98) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/main/Execution/Entity/index.d.ts +1 -1
  3. package/dist/main/Execution/Entity/index.js +5 -3
  4. package/dist/main/Execution/Entity/index.js.map +1 -1
  5. package/dist/main/Execution/EntityFlowModals/confirmFlow.js +33 -6
  6. package/dist/main/Execution/EntityFlowModals/confirmFlow.js.map +1 -1
  7. package/dist/main/Execution/FlowModals/FlowModal.d.ts +1 -0
  8. package/dist/main/Execution/FlowModals/FlowModal.js.map +1 -1
  9. package/dist/main/Execution/FlowModals/confirmFlow.js +15 -3
  10. package/dist/main/Execution/FlowModals/confirmFlow.js.map +1 -1
  11. package/dist/main/Execution/FormsExecution/Field.js +26 -9
  12. package/dist/main/Execution/FormsExecution/Field.js.map +1 -1
  13. package/dist/main/Execution/FormsExecution/FieldWithAttribute.d.ts +3 -2
  14. package/dist/main/Execution/FormsExecution/FieldWithAttribute.js +15 -8
  15. package/dist/main/Execution/FormsExecution/FieldWithAttribute.js.map +1 -1
  16. package/dist/main/Execution/FormsExecution/Form.js +3 -1
  17. package/dist/main/Execution/FormsExecution/Form.js.map +1 -1
  18. package/dist/main/Execution/FormsExecution/TranslatableField/index.js +2 -0
  19. package/dist/main/Execution/FormsExecution/TranslatableField/index.js.map +1 -1
  20. package/dist/main/Execution/FormsExecution/WithProperties.js +1 -1
  21. package/dist/main/Execution/FormsExecution/WithProperties.js.map +1 -1
  22. package/dist/main/Execution/FormsExecution/constants/props/booleanProps.js +1 -0
  23. package/dist/main/Execution/FormsExecution/constants/props/booleanProps.js.map +1 -1
  24. package/dist/main/Execution/FormsExecution/events/setAjaxFormResponse.js +84 -23
  25. package/dist/main/Execution/FormsExecution/events/setAjaxFormResponse.js.map +1 -1
  26. package/dist/main/Execution/FormsExecution/fields/Captcha/index.js +2 -0
  27. package/dist/main/Execution/FormsExecution/fields/Captcha/index.js.map +1 -1
  28. package/dist/main/Execution/FormsExecution/fields/Editor/index.d.ts +2 -0
  29. package/dist/main/Execution/FormsExecution/fields/Editor/index.js +15 -0
  30. package/dist/main/Execution/FormsExecution/fields/Editor/index.js.map +1 -1
  31. package/dist/main/Execution/FormsExecution/fields/File/index.js +2 -2
  32. package/dist/main/Execution/FormsExecution/fields/File/index.js.map +1 -1
  33. package/dist/main/Execution/FormsExecution/fields/Grid/GridFooterHandler.d.ts +2 -0
  34. package/dist/main/Execution/FormsExecution/fields/Grid/GridFooterHandler.js +16 -12
  35. package/dist/main/Execution/FormsExecution/fields/Grid/GridFooterHandler.js.map +1 -1
  36. package/dist/main/Execution/FormsExecution/fields/Grid/index.d.ts +12 -3
  37. package/dist/main/Execution/FormsExecution/fields/Grid/index.js +179 -53
  38. package/dist/main/Execution/FormsExecution/fields/Grid/index.js.map +1 -1
  39. package/dist/main/Execution/FormsExecution/fields/Grid/types.d.ts +6 -1
  40. package/dist/main/Execution/FormsExecution/fields/GridPaginated/index.d.ts +11 -1
  41. package/dist/main/Execution/FormsExecution/fields/GridPaginated/index.js +82 -33
  42. package/dist/main/Execution/FormsExecution/fields/GridPaginated/index.js.map +1 -1
  43. package/dist/main/Execution/FormsExecution/fields/Input/index.js +1 -1
  44. package/dist/main/Execution/FormsExecution/fields/Input/index.js.map +1 -1
  45. package/dist/main/Execution/FormsExecution/fields/ModalInput/index.d.ts +1 -1
  46. package/dist/main/Execution/FormsExecution/fields/ModalInput/index.js +65 -18
  47. package/dist/main/Execution/FormsExecution/fields/ModalInput/index.js.map +1 -1
  48. package/dist/main/Execution/FormsExecution/fields/Multiple/index.js +1 -1
  49. package/dist/main/Execution/FormsExecution/fields/Multiple/index.js.map +1 -1
  50. package/dist/main/Execution/FormsExecution/types.d.ts +1 -0
  51. package/dist/main/Execution/Signature/SignatureController.d.ts +110 -8
  52. package/dist/main/Execution/Signature/SignatureController.js +252 -9
  53. package/dist/main/Execution/Signature/SignatureController.js.map +1 -1
  54. package/dist/main/Execution/Signature/TProvider.d.ts +14 -0
  55. package/dist/main/Execution/Signature/TProvider.d.ts.map +1 -0
  56. package/dist/main/Execution/Signature/TProviderStatus.d.ts +13 -0
  57. package/dist/main/Execution/Signature/TProviderStatus.d.ts.map +1 -0
  58. package/dist/main/Execution/Uploader/FormsUploader.d.ts +21 -0
  59. package/dist/main/Execution/Uploader/FormsUploader.js +31 -5
  60. package/dist/main/Execution/Uploader/FormsUploader.js.map +1 -1
  61. package/dist/main/Execution/Uploader/UploaderApi.d.ts +2 -0
  62. package/dist/main/Execution/Uploader/UploaderApi.js +19 -0
  63. package/dist/main/Execution/Uploader/UploaderApi.js.map +1 -1
  64. package/dist/main/Execution/index.d.ts +22 -3
  65. package/dist/main/Execution/index.js +92 -39
  66. package/dist/main/Execution/index.js.map +1 -1
  67. package/dist/main/Execution/types.d.ts +1 -0
  68. package/dist/main/Execution/types.js.map +1 -1
  69. package/dist/main/InitialData/types/fields/TApiaFieldProperties.d.ts +1 -0
  70. package/dist/programming/ApiaFieldWithAttribute.d.ts +3 -3
  71. package/dist/programming/ApiaFieldWithAttribute.js +4 -4
  72. package/dist/programming/ApiaFieldWithAttribute.js.map +1 -1
  73. package/dist/programming/constants/BooleanProps.js +1 -0
  74. package/dist/programming/constants/BooleanProps.js.map +1 -1
  75. package/dist/programming/fields/CheckField.d.ts +2 -2
  76. package/dist/programming/fields/CheckField.js +2 -2
  77. package/dist/programming/fields/CheckField.js.map +1 -1
  78. package/dist/programming/fields/FileUploaderField.d.ts +2 -2
  79. package/dist/programming/fields/FileUploaderField.js +2 -5
  80. package/dist/programming/fields/FileUploaderField.js.map +1 -1
  81. package/dist/programming/fields/GridField.d.ts +5 -6
  82. package/dist/programming/fields/GridField.js +31 -46
  83. package/dist/programming/fields/GridField.js.map +1 -1
  84. package/dist/programming/fields/InputField.d.ts +2 -2
  85. package/dist/programming/fields/InputField.js +10 -3
  86. package/dist/programming/fields/InputField.js.map +1 -1
  87. package/dist/programming/fields/ModalInput.d.ts +3 -2
  88. package/dist/programming/fields/ModalInput.js +4 -7
  89. package/dist/programming/fields/ModalInput.js.map +1 -1
  90. package/dist/programming/fields/MultipleField.d.ts +2 -2
  91. package/dist/programming/fields/MultipleField.js +12 -5
  92. package/dist/programming/fields/MultipleField.js.map +1 -1
  93. package/dist/programming/fields/TreeField.d.ts +1 -1
  94. package/dist/programming/fields/TreeField.js +1 -1
  95. package/dist/programming/fields/TreeField.js.map +1 -1
  96. package/dist/util/xml/parseXml.js +3 -0
  97. package/dist/util/xml/parseXml.js.map +1 -1
  98. package/package.json +7 -7
@@ -6,7 +6,7 @@ import { Field } from '../../Field.js';
6
6
  import { parseFakeJSON } from '../../../../../util/other/parseFakeJSON.js';
7
7
  import { GridFooterHandler } from './GridFooterHandler.js';
8
8
  import { GridCell } from './GridCell.js';
9
- import { Mutex, arrayOrArray } from '@apia/util';
9
+ import { Mutex, arrayOrArray, isTrue } from '@apia/util';
10
10
  import { AdditionalCell } from './AdditionalCell.js';
11
11
  import { setAjaxFormResponse } from '../../events/setAjaxFormResponse.js';
12
12
  import { File } from '../File/index.js';
@@ -32,6 +32,18 @@ async function inlineTimeout(cb, _t) {
32
32
  setTimeout(cb, _t);
33
33
  return Promise.resolve(true);
34
34
  }
35
+ const restoreBodyRows = (controller, rows) => {
36
+ rows.forEach((row) => {
37
+ row.setTable(controller);
38
+ row.setContainer(controller.body);
39
+ });
40
+ controller.body.setState("rows", rows);
41
+ };
42
+ const getGridStatesRowCount = (states, includeFirstRow) => Math.max(
43
+ includeFirstRow && states.length > 0 ? 1 : 0,
44
+ 0,
45
+ ...states.map((fieldStates) => fieldStates.length)
46
+ );
35
47
  class Grid extends Field {
36
48
  constructor(definition) {
37
49
  const parsedDefinition = Grid.parseGridDefinition(definition);
@@ -68,23 +80,27 @@ class Grid extends Field {
68
80
  __publicField(this, "tableController");
69
81
  const fieldsArray = arrayOrArray(field);
70
82
  this.initialStates = fieldsArray.map(
71
- (current) => current.fieldValue || current.row ? arrayOrArray(current.fieldValue || current.row) : void 0
72
- ).filter(Boolean);
83
+ (current) => arrayOrArray(current.fieldValue || current.row)
84
+ );
73
85
  this.fieldsDefinitions = fieldsArray.map(
74
86
  ({ fieldValue, properties: properties2, ...current }) => {
75
87
  return { ...current, properties: parseFakeJSON(properties2) };
76
88
  }
77
89
  );
78
90
  this.state.header = arrayOrArray(parsedDefinition.gridHeader.col).map(
79
- (c) => ({
80
- fldId: c.fldId,
81
- label: c.colTitle,
82
- title: c.title,
83
- width: c.colWidth || this.resolveHeaderWidth(c),
84
- hidden: false,
85
- required: false,
86
- fldType: c.fldType
87
- })
91
+ (c) => {
92
+ const defaultWidth = this.resolveHeaderWidth(c);
93
+ return {
94
+ fldId: c.fldId,
95
+ label: c.colTitle,
96
+ title: c.title,
97
+ width: c.colWidth || defaultWidth,
98
+ defaultWidth,
99
+ hidden: false,
100
+ required: false,
101
+ fldType: c.fldType
102
+ };
103
+ }
88
104
  );
89
105
  this.state.isLoading = false;
90
106
  this.state.isMaximized = false;
@@ -92,6 +108,11 @@ class Grid extends Field {
92
108
  get controller() {
93
109
  return this.tableController;
94
110
  }
111
+ get isSmallGridMode() {
112
+ const execution = this.getForm()?.execution;
113
+ const dataGridConfig = (execution?.environment ? getWindow(execution) : globalThis.window)?.config?.execution?.components?.dataGrid;
114
+ return dataGridConfig?.gridView === "small";
115
+ }
95
116
  get currentPage() {
96
117
  return this.properties.currentPage;
97
118
  }
@@ -102,7 +123,13 @@ class Grid extends Field {
102
123
  * Returns the final index of the current page
103
124
  */
104
125
  get finalIndex() {
105
- return (this.controller.body.rows.at(-1)?.cells.find((c) => c instanceof GridCell)).getField().definition.index;
126
+ let lastGridCell;
127
+ for (let rowIndex = this.controller.body.rows.length - 1; rowIndex >= 0 && !lastGridCell; rowIndex--) {
128
+ lastGridCell = this.controller.body.rows[rowIndex].cells.find(
129
+ (cell) => cell instanceof GridCell
130
+ );
131
+ }
132
+ return lastGridCell?.getField().definition.index ?? this.startIndex + this.controller.body.rows.length - 1;
106
133
  }
107
134
  get footerController() {
108
135
  return this._footerController;
@@ -116,6 +143,32 @@ class Grid extends Field {
116
143
  get length() {
117
144
  return this.tableController.body.rows.length;
118
145
  }
146
+ async ensureRenderedRowsCount(rowsCount) {
147
+ const totalRowsCount = Math.max(0, Math.floor(rowsCount));
148
+ const targetRowsCount = this.isPaged ? Math.min(
149
+ this.pageSize,
150
+ Math.max(0, totalRowsCount - this.startIndex)
151
+ ) : totalRowsCount;
152
+ for (let index = this.length; index < targetRowsCount; index++) {
153
+ await this.addRowFromDefinitions(
154
+ false,
155
+ this.fieldsDefinitions.map((definition, columnIndex) => ({
156
+ ...definition,
157
+ ...this.initialStates[columnIndex]?.[index]
158
+ }))
159
+ );
160
+ }
161
+ }
162
+ get hasReachedMaxRows() {
163
+ const maxRows = Number(this.properties.maxRows);
164
+ if (!Number.isFinite(maxRows) || maxRows <= 0)
165
+ return false;
166
+ const declaredRows = Number(
167
+ this.definition.rowCount
168
+ );
169
+ const rowsCount = this.isPaged && Number.isFinite(declaredRows) ? Math.max(declaredRows, this.startIndex + this.length) : this.length;
170
+ return rowsCount >= maxRows;
171
+ }
119
172
  get minIndex() {
120
173
  return Number.isFinite(this.properties.pageSize) ? (this.properties.currentPage - 1) * this.properties.pageSize : 0;
121
174
  }
@@ -176,10 +229,49 @@ class Grid extends Field {
176
229
  ].join("__");
177
230
  }
178
231
  resolveHeaderWidth(c) {
232
+ const narrowWidth = this.isSmallGridMode ? "180px" : "150px";
233
+ const defaultWidth = this.isSmallGridMode ? "220px" : "230px";
179
234
  if (c.fldType === "3") {
180
- return "150px";
235
+ return narrowWidth;
181
236
  }
182
- return "230px";
237
+ return defaultWidth;
238
+ }
239
+ shouldShowAdditionalColumn() {
240
+ return this.isSmallGridMode || this.properties.gridForm || !this.properties.hideDelButton && !this.properties.readonly && !this.properties.inputAsText && !this.getForm().definition.readOnly && !this.getForm().definition.readonly && getWindow(this.getForm().execution)?.config?.execution?.components?.dataGrid?.showDeleteButton;
241
+ }
242
+ hasPercentageColumnWidths() {
243
+ return this.header.some(
244
+ (col) => String(col.width || "").trim().endsWith("%")
245
+ );
246
+ }
247
+ parsePercentWidth(width) {
248
+ const normalizedWidth = String(width ?? "").trim();
249
+ if (!normalizedWidth.endsWith("%"))
250
+ return null;
251
+ const parsed = Number.parseFloat(normalizedWidth);
252
+ return Number.isFinite(parsed) ? parsed : null;
253
+ }
254
+ getHeaderWidthContext(hiddenColumns) {
255
+ const visibleColumns = this.header.filter(
256
+ (col) => !hiddenColumns.has(col.fldId)
257
+ );
258
+ const totalPercent = visibleColumns.reduce(
259
+ (total, col) => total + (this.parsePercentWidth(col.width) ?? 0),
260
+ 0
261
+ );
262
+ return { totalPercent };
263
+ }
264
+ normalizeHeaderWidth(width, widthContext) {
265
+ const normalizedWidth = String(width ?? 200).trim();
266
+ const percentWidth = this.parsePercentWidth(normalizedWidth);
267
+ if (percentWidth !== null && widthContext?.totalPercent) {
268
+ const percentShare = percentWidth / widthContext.totalPercent;
269
+ return `${percentShare * 100}%`;
270
+ }
271
+ if (normalizedWidth.endsWith("%") || normalizedWidth.endsWith("px")) {
272
+ return normalizedWidth;
273
+ }
274
+ return `${normalizedWidth}px`;
183
275
  }
184
276
  getGridActionFromEventName(eventName) {
185
277
  switch (eventName) {
@@ -194,8 +286,11 @@ class Grid extends Field {
194
286
  }
195
287
  }
196
288
  fireServerEvent(eventName, params) {
289
+ const focusedCell = this.controller.getFocusedCell();
197
290
  return super.fireServerEvent(eventName, {
198
291
  gridAction: this.getGridActionFromEventName(eventName),
292
+ gridFocusedRow: focusedCell?.getRow()?.getIndex() === void 0 ? void 0 : focusedCell.getRow().getIndex() + this.startIndex,
293
+ gridFocusedColumn: focusedCell?.getState("colName"),
199
294
  ...params
200
295
  });
201
296
  }
@@ -219,8 +314,8 @@ class Grid extends Field {
219
314
  const xml = Grid.parseGridDefinition(response.data.gridXml);
220
315
  const fieldsArray = arrayOrArray(xml.field);
221
316
  this.newRowStates = fieldsArray.map(
222
- (current) => current.fieldValue || current.row ? arrayOrArray(current.fieldValue || current.row) : void 0
223
- ).filter(Boolean);
317
+ (current) => arrayOrArray(current.fieldValue || current.row)
318
+ );
224
319
  } else {
225
320
  throw new Error(
226
321
  !getWindow(this.form.execution).SERVER_MODE ? "Something went wrong on the add row action." : ""
@@ -230,7 +325,7 @@ class Grid extends Field {
230
325
  true,
231
326
  this.fieldsDefinitions.map((c, i) => ({
232
327
  ...c,
233
- ...this.newRowStates[i][0]
328
+ ...this.newRowStates[i]?.[0]
234
329
  }))
235
330
  );
236
331
  return await (this.hasServerAjaxEventsOfType("gridAdd") ? inlineCaller : inlineTimeout)(async () => {
@@ -283,7 +378,7 @@ class Grid extends Field {
283
378
  setAjaxFormResponse(this.form.execution, parseXml(evs));
284
379
  }
285
380
  if (!(await res)?.data?.success) {
286
- this.tableController.body.setState("rows", currentRows);
381
+ restoreBodyRows(this.tableController, currentRows);
287
382
  this.tableController.setState("selection", currentSelection);
288
383
  return false;
289
384
  }
@@ -293,7 +388,7 @@ class Grid extends Field {
293
388
  /**
294
389
  * @param index Si se pasa, se borran el o los índices provistos. Sino, se borran las filas seleccionadas, si es que hay alguna.
295
390
  */
296
- async deleteRows(index) {
391
+ async deleteRows(index, options) {
297
392
  return this.asyncAction(async () => {
298
393
  if (void 0 === index) {
299
394
  index = [...this.controller.getState("selection")].map((c) => {
@@ -306,7 +401,8 @@ class Grid extends Field {
306
401
  if (this.hasServerNoAjaxEventsOfType("gridDelete")) {
307
402
  await this.fireServerEvent("gridDelete", {
308
403
  gridAction: "delete",
309
- rowId: deletingIndices
404
+ rowId: deletingIndices,
405
+ ...options
310
406
  });
311
407
  } else {
312
408
  let minIndex = Infinity;
@@ -320,7 +416,8 @@ class Grid extends Field {
320
416
  postData: {
321
417
  gridAction: "delete",
322
418
  rowId: deletingIndices,
323
- fireEvents: this.hasServerAjaxEventsOfType("gridDelete")
419
+ fireEvents: this.hasServerAjaxEventsOfType("gridDelete"),
420
+ ...options
324
421
  }
325
422
  });
326
423
  const currentRows = [...this.tableController.body.rows];
@@ -328,7 +425,7 @@ class Grid extends Field {
328
425
  this.tableController.getState("selection")
329
426
  );
330
427
  deletingIndices.forEach(
331
- (c) => this.controller.body.getRowByIndex(c).remove()
428
+ (c) => this.controller.body.getRowByIndex(c)?.remove()
332
429
  );
333
430
  for (let i = minIndex; i < this.controller.body.rows.length; i++) {
334
431
  this.controller.body.getRowByIndex(i).cells.forEach((c) => {
@@ -350,9 +447,9 @@ class Grid extends Field {
350
447
  if (evs) {
351
448
  setAjaxFormResponse(this.form.execution, parseXml(evs));
352
449
  }
353
- const scriptResult = await this.fireScriptEvent("gridAdd");
450
+ const scriptResult = await this.fireScriptEvent("gridDelete");
354
451
  if (!scriptResult || !(await res)?.data?.success) {
355
- this.tableController.body.setState("rows", currentRows);
452
+ restoreBodyRows(this.tableController, currentRows);
356
453
  this.tableController.setState("selection", currentSelection);
357
454
  return false;
358
455
  }
@@ -472,7 +569,10 @@ class Grid extends Field {
472
569
  for (let i = 0; i < this.tableController.head.rows[0]?.cells.length || 0; i++) {
473
570
  for (const row of this.tableController.head.rows) {
474
571
  const cell = row.cells[i];
475
- if (cell instanceof HeaderCell && cell.getState("isHidden")) {
572
+ const fieldDefinition = this.fieldsDefinitions.find(
573
+ (definition) => definition.id === cell.getState("colName")
574
+ );
575
+ if (cell instanceof HeaderCell && (fieldDefinition?.properties.visibilityHidden || fieldDefinition?.properties.displayNone || fieldDefinition?.fieldType === "hidden")) {
476
576
  shownColumns.delete(cell.getState("colName"));
477
577
  break;
478
578
  }
@@ -502,10 +602,14 @@ class Grid extends Field {
502
602
  );
503
603
  this._footerController = new GridFooterHandler(this);
504
604
  this.controller.on("columnSort", (col) => {
505
- this.sortColumn(col.getState("properties").col.fldId);
605
+ const column = col.getState("properties")?.col;
606
+ if (column) {
607
+ this.sortColumn(column.fldId);
608
+ }
506
609
  });
507
610
  const headerRow = new Row("header");
508
- if (this.properties.gridForm || !this.properties.hideDelButton && !this.properties.readonly && !this.properties.inputAsText && !this.getForm().definition.readOnly && !this.getForm().definition.readonly && getWindow(this.getForm().execution)?.config?.execution?.components?.dataGrid?.showDeleteButton)
611
+ const hasAdditionalColumn = this.shouldShowAdditionalColumn();
612
+ if (hasAdditionalColumn)
509
613
  headerRow.addCell(
510
614
  new AdditionalCell(
511
615
  this,
@@ -519,26 +623,28 @@ class Grid extends Field {
519
623
  hiddenColumns.add(c.fldId);
520
624
  });
521
625
  for (const def of this.fieldsDefinitions) {
522
- if (!def.properties.visibilityHidden && def.fieldType !== "hidden") {
626
+ if (!def.properties.visibilityHidden && !def.properties.displayNone && def.fieldType !== "hidden") {
523
627
  hiddenColumns.delete(def.id);
524
628
  }
525
629
  }
526
- for (let index = 0; index < this.initialStates[0]?.length || 0; index++) {
630
+ const initialRowsCount = getGridStatesRowCount(
631
+ this.initialStates,
632
+ isTrue(this.getProperty("includeFirstRow"))
633
+ );
634
+ for (let index = 0; index < initialRowsCount; index++) {
527
635
  await this.addRowFromDefinitions(
528
636
  false,
529
637
  this.fieldsDefinitions.map((c, i) => {
530
638
  return {
531
639
  ...c,
532
- ...this.initialStates[i][index]
640
+ ...this.initialStates[i]?.[index]
533
641
  };
534
642
  })
535
643
  );
536
644
  }
645
+ const widthContext = this.getHeaderWidthContext(hiddenColumns);
537
646
  this.header.forEach((col, i) => {
538
- let width = String(col.width || 200);
539
- if (!width.endsWith("px")) {
540
- width = `${width}px`;
541
- }
647
+ const width = this.normalizeHeaderWidth(col.width, widthContext);
542
648
  headerRow.addCell(
543
649
  new HeaderCell(this, {
544
650
  colName: col.fldId || String(i),
@@ -621,7 +727,7 @@ class Grid extends Field {
621
727
  );
622
728
  if (this.hasServerNoAjaxEventsOfType("gridSort")) {
623
729
  await this.fireServerEvent("gridSort", {
624
- gridAction: "down",
730
+ gridAction: "up",
625
731
  rowId: indices
626
732
  });
627
733
  } else {
@@ -666,6 +772,8 @@ class Grid extends Field {
666
772
  this.calculateMustShowAdditionalColumn();
667
773
  }
668
774
  async validate() {
775
+ if (this.properties.displayNone)
776
+ return true;
669
777
  let isValid = true;
670
778
  let firstInvalid = null;
671
779
  for await (const row of this.tableController.body.rows) {
@@ -683,13 +791,17 @@ class Grid extends Field {
683
791
  return isValid || firstInvalid;
684
792
  }
685
793
  async actualRefreshAction() {
794
+ const previousVisibilityHidden = this.properties.visibilityHidden;
686
795
  const res = await this.runAction({
687
796
  postData: {
688
797
  gridAction: "refresh"
689
798
  }
690
799
  });
691
800
  if (res?.data?.gridXml) {
692
- await this.rebuildGrid(res.data.gridXml, { recreateRows: true });
801
+ await this.rebuildGrid(res.data.gridXml, {
802
+ recreateRows: true,
803
+ previousVisibilityHidden
804
+ });
693
805
  } else {
694
806
  throw new Error("The server didn't return a valid XML response.");
695
807
  }
@@ -704,7 +816,7 @@ class Grid extends Field {
704
816
  this.getForm().addFieldToRender(current.id, index);
705
817
  return {
706
818
  ...current,
707
- ...this.initialStates[columnIndex][0]
819
+ ...this.initialStates[columnIndex]?.[0]
708
820
  };
709
821
  });
710
822
  }
@@ -712,7 +824,7 @@ class Grid extends Field {
712
824
  cells: [],
713
825
  isSelectable: true
714
826
  });
715
- if (this.properties.gridForm || !this.properties.hideDelButton && !this.properties.readonly && !this.properties.inputAsText && !this.getForm().definition.readOnly && !this.getForm().definition.readonly && getWindow(this.getForm().execution)?.config?.execution?.components?.dataGrid?.showDeleteButton)
827
+ if (this.isSmallGridMode || this.properties.gridForm || !this.properties.hideDelButton && !this.properties.readonly && !this.properties.inputAsText && !this.getForm().definition.readOnly && !this.getForm().definition.readonly && getWindow(this.getForm().execution)?.config?.execution?.components?.dataGrid?.showDeleteButton)
716
828
  newRow.addCell(
717
829
  new AdditionalCell(
718
830
  this,
@@ -748,12 +860,6 @@ class Grid extends Field {
748
860
  this.managedFieldsNames.add(newField.properties.name);
749
861
  if (!(newField instanceof Hidden)) {
750
862
  this.cache.set(index, newField.definition.id, newField);
751
- let width = String(
752
- this.header.find((c) => c.fldId === field.id)?.width || 250
753
- );
754
- if (!width.endsWith("px")) {
755
- width = `${width}px`;
756
- }
757
863
  newRow.addCell(
758
864
  new GridCell({
759
865
  colName: newField.definition.id,
@@ -790,7 +896,7 @@ class Grid extends Field {
790
896
  }
791
897
  calculateMustShowAdditionalColumn() {
792
898
  const { hideDelButton, shownDeleteButtons, shownEditionButtons, gridForm } = this.properties;
793
- const mustShowAdditionalColumn = !hideDelButton && [...shownDeleteButtons.values()].some((c) => c !== false) || !!gridForm && [...shownEditionButtons.values()].some((c) => c !== false);
899
+ const mustShowAdditionalColumn = this.isSmallGridMode || !hideDelButton && [...shownDeleteButtons.values()].some((c) => c !== false) || !!gridForm && [...shownEditionButtons.values()].some((c) => c !== false);
794
900
  this.controller.toggleColumnVisibility(
795
901
  "additional",
796
902
  mustShowAdditionalColumn
@@ -801,21 +907,39 @@ class Grid extends Field {
801
907
  }
802
908
  async rebuildGrid(xmlString, options) {
803
909
  const xml = Grid.parseGridDefinition(xmlString);
910
+ const preserveColumnVisibilities = options?.previousVisibilityHidden !== void 0 && xml.properties.visibilityHidden !== void 0 && isTrue(xml.properties.visibilityHidden) !== isTrue(options.previousVisibilityHidden);
804
911
  const fieldsArray = arrayOrArray(xml.field);
805
912
  const statesArray = fieldsArray.map(
806
913
  (field) => arrayOrArray(field.fieldValue || field.row)
807
914
  );
808
- const rowCount = statesArray[0]?.length || 0;
915
+ const rowCount = getGridStatesRowCount(
916
+ statesArray,
917
+ isTrue(
918
+ xml.properties.includeFirstRow ?? this.getProperty("includeFirstRow")
919
+ )
920
+ );
809
921
  this.properties.pages = xml.pages || this.properties.pages;
810
922
  this.properties.currentPage = xml.curPage || this.properties.currentPage;
811
923
  this.properties.visibilityHidden = xml.properties.visibilityHidden ?? this.properties.visibilityHidden;
924
+ this.properties.displayNone = xml.properties.displayNone ?? this.properties.displayNone;
925
+ if (xml.properties.readonly !== void 0) {
926
+ this.setProperty("readonly", isTrue(xml.properties.readonly));
927
+ }
812
928
  if (options?.recreateRows) {
813
929
  this.cache.clear();
814
930
  this.controller.clearSelection();
815
931
  this.controller.body.clear();
816
932
  this.fieldsDefinitions = fieldsArray.map(
817
933
  ({ fieldValue, properties, ...current }) => {
818
- return { ...current, properties: parseFakeJSON(properties) };
934
+ const parsedProperties = parseFakeJSON(properties);
935
+ const previousDefinition = this.fieldsDefinitions.find(
936
+ (definition) => definition.id === current.id
937
+ );
938
+ if (preserveColumnVisibilities && previousDefinition) {
939
+ parsedProperties.visibilityHidden = previousDefinition.properties.visibilityHidden;
940
+ parsedProperties.displayNone = previousDefinition.properties.displayNone;
941
+ }
942
+ return { ...current, properties: parsedProperties };
819
943
  }
820
944
  );
821
945
  for (let i = 0; i < rowCount; i++) {
@@ -830,7 +954,7 @@ class Grid extends Field {
830
954
  ...field,
831
955
  index: i,
832
956
  fieldValue: {
833
- ...statesArray[columnIndex][i]
957
+ ...statesArray[columnIndex]?.[i]
834
958
  }
835
959
  };
836
960
  });
@@ -850,7 +974,7 @@ class Grid extends Field {
850
974
  ...field,
851
975
  index: i,
852
976
  fieldValue: {
853
- ...statesArray[columnIndex][i]
977
+ ...statesArray[columnIndex]?.[i]
854
978
  }
855
979
  };
856
980
  });
@@ -889,7 +1013,7 @@ class Grid extends Field {
889
1013
  } else if (field instanceof ModalInput) {
890
1014
  field.setValue(
891
1015
  {
892
- showValue: state.qry_show_value || "",
1016
+ showValue: state.qry_show_value ?? state.value ?? "",
893
1017
  storeValue: state.value || ""
894
1018
  },
895
1019
  { force: true }
@@ -947,13 +1071,15 @@ class Grid extends Field {
947
1071
  toggleMaximize() {
948
1072
  this.state.isMaximized = !this.state.isMaximized;
949
1073
  this.getForm().execution.environment.localStorage.setItem(
950
- `${this.definition.id}__isMaximized`,
1074
+ this.getMaximizedStorageKey(),
951
1075
  String(this.state.isMaximized)
952
1076
  );
953
1077
  }
954
1078
  clearMaximizeState() {
955
1079
  this.state.isMaximized = false;
956
- localStorage.removeItem(this.getMaximizedStorageKey());
1080
+ this.getForm().execution.environment.localStorage.removeItem(
1081
+ this.getMaximizedStorageKey()
1082
+ );
957
1083
  }
958
1084
  }
959
1085