@guiexpert/table 1.1.92 → 1.1.94

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 (68) hide show
  1. package/README.md +13 -0
  2. package/css/main.css +142 -0
  3. package/css/table-classes.css +34 -0
  4. package/css/table-color-vars.css +32 -0
  5. package/css/table-pivot.css +42 -0
  6. package/css/table-row-group.css +25 -0
  7. package/css/table-tree.css +9 -0
  8. package/index.cjs +44 -36
  9. package/index.d.ts +39 -0
  10. package/index.js +6247 -3509
  11. package/lib/table/aggregation/aggregate-internals.d.ts +30 -0
  12. package/lib/table/aggregation/aggregate-spec.if.d.ts +51 -0
  13. package/lib/table/aggregation/aggregate.d.ts +58 -0
  14. package/lib/table/aggregation/aggregator-name.type.d.ts +39 -0
  15. package/lib/table/aggregation/aggregator.if.d.ts +51 -0
  16. package/lib/table/aggregation/aggregators.d.ts +37 -0
  17. package/lib/table/aggregation/create-value-getter.d.ts +18 -0
  18. package/lib/table/aggregation/selection-aggregates.if.d.ts +35 -0
  19. package/lib/table/aggregation/value-accessor.type.d.ts +13 -0
  20. package/lib/table/data/common/row-number-column-def.d.ts +107 -0
  21. package/lib/table/data/common/row-number-columns.d.ts +17 -0
  22. package/lib/table/data/common/row-number-options.d.ts +19 -0
  23. package/lib/table/data/common/row-number-options.if.d.ts +44 -0
  24. package/lib/table/data/tablemodel/areamodel/aggregate-footer-options.if.d.ts +73 -0
  25. package/lib/table/data/tablemodel/areamodel/area-model-aggregate-footer.d.ts +145 -0
  26. package/lib/table/data/tablemodel/areamodel/area-model-cell-groups.d.ts +18 -1
  27. package/lib/table/data/tablemodel/areamodel/area-model-pivot-footer.d.ts +47 -0
  28. package/lib/table/data/tablemodel/areamodel/area-model-pivot.d.ts +250 -0
  29. package/lib/table/data/tablemodel/areamodel/area-model-row-groups.d.ts +314 -0
  30. package/lib/table/data/tablemodel/areamodel/area-model-tree.d.ts +14 -0
  31. package/lib/table/data/tablemodel/areamodel/area-model.if.d.ts +39 -0
  32. package/lib/table/data/tablemodel/areamodel/derived-values-change.if.d.ts +30 -0
  33. package/lib/table/factory/pivot-factory.d.ts +63 -0
  34. package/lib/table/factory/pivot-table-model-para.if.d.ts +44 -0
  35. package/lib/table/factory/row-group-factory.d.ts +70 -0
  36. package/lib/table/factory/row-group-table-model-para.if.d.ts +66 -0
  37. package/lib/table/factory/table-factory.d.ts +45 -1
  38. package/lib/table/instanceof-workaround.d.ts +143 -6
  39. package/lib/table/pivot/area-model-pivot-header.d.ts +9 -0
  40. package/lib/table/pivot/pivot-column-def.d.ts +28 -0
  41. package/lib/table/pivot/pivot-column-info.if.d.ts +25 -0
  42. package/lib/table/pivot/pivot-config.if.d.ts +58 -0
  43. package/lib/table/pivot/pivot-internals.d.ts +13 -0
  44. package/lib/table/pivot/pivot-layout.d.ts +40 -0
  45. package/lib/table/pivot/pivot-result.d.ts +157 -0
  46. package/lib/table/pivot/pivot-table-model.d.ts +86 -0
  47. package/lib/table/pivot/pivot-value.type.d.ts +67 -0
  48. package/lib/table/render-scope.d.ts +61 -4
  49. package/lib/table/renderer/aggregate-cell-renderer.d.ts +27 -0
  50. package/lib/table/renderer/row-number-cell-renderer.d.ts +27 -0
  51. package/lib/table/rowgroup/group-rows-internals.d.ts +14 -0
  52. package/lib/table/rowgroup/group-rows-options.if.d.ts +13 -0
  53. package/lib/table/rowgroup/group-rows.d.ts +48 -0
  54. package/lib/table/rowgroup/row-group-column-def.d.ts +26 -0
  55. package/lib/table/rowgroup/row-group-column-options.if.d.ts +27 -0
  56. package/lib/table/rowgroup/row-group-detail-row.d.ts +8 -0
  57. package/lib/table/rowgroup/row-group-field.type.d.ts +56 -0
  58. package/lib/table/rowgroup/row-group-internals.d.ts +31 -0
  59. package/lib/table/rowgroup/row-group-layout.d.ts +13 -0
  60. package/lib/table/rowgroup/row-group-model-options.if.d.ts +39 -0
  61. package/lib/table/rowgroup/row-group.d.ts +51 -0
  62. package/lib/table/rowgroup/row-group.if.d.ts +48 -0
  63. package/lib/table/selection/selection-aggregator.d.ts +37 -0
  64. package/lib/table/selection/selection-service.d.ts +7 -0
  65. package/lib/table/service/convenience-dom.service.d.ts +5 -0
  66. package/lib/table/table-api.d.ts +112 -1
  67. package/lib/table/table-scope.d.ts +19 -0
  68. package/package.json +3 -2
@@ -51,6 +51,13 @@ export declare class SelectionService implements OnActionTriggeredIf {
51
51
  */
52
52
  onMouseClicked(evt: GeMouseEvent, _previousEvt: GeMouseEvent | undefined): boolean;
53
53
  onActionTriggered(actionId: ActionId): boolean;
54
+ /** True if the column is a row number column ({@link RowNumberColumnDef}). */
55
+ private isRowNumberColumn;
56
+ /** A click on the header cell of the row numbers: everything (selection types "row" and "range"). */
57
+ private selectAllByRowNumberHeader;
58
+ /** Selection type "range", click on a row number: the whole row – new, toggled (Ctrl/⌘) or removed (Ctrl/⌘+Alt). */
59
+ private clickRowNumber;
60
+ private static isRangeSelection;
54
61
  /** Speaks a message for screen readers – only if the selection model can select anything. */
55
62
  private announce;
56
63
  /** Runs `fn` so that all selection changes in it reach the table's listener as ONE onSelectionChanged event. */
@@ -26,6 +26,11 @@ export interface AddColumnDivPara {
26
26
  sortState?: SortState;
27
27
  /** Accessible name of the row checkbox (`showCheckboxWihoutExtraColumn`), e.g. "Select row 5". @since 1.1.91 */
28
28
  checkboxAriaLabel?: string;
29
+ /**
30
+ * Index of the first data column – the column of the checkbox of `showCheckboxWihoutExtraColumn` and of the tree
31
+ * label. 0, behind a {@link RowNumberColumnDef} 1. Default 0. @since 1.1.93
32
+ */
33
+ firstDataColumnIndex?: number;
29
34
  }
30
35
  /** @category DOM */
31
36
  export declare class ConvenienceDomService {
@@ -10,6 +10,9 @@ import { ShortcutActionIdMapping } from './action/shortcut-actionid-mapping.type
10
10
  import { SelectionModelIf } from './selection/selection-model.if.js';
11
11
  import { TableModelIf } from './data/tablemodel/table-model.if.js';
12
12
  import { AreaModelIf } from './data/tablemodel/areamodel/area-model.if.js';
13
+ import { PivotConfigIf } from './pivot/pivot-config.if.js';
14
+ import { RowGroupField } from './rowgroup/row-group-field.type.js';
15
+ import { SelectionAggregatesIf } from './aggregation/selection-aggregates.if.js';
13
16
 
14
17
  /**
15
18
  * The public API of one table – everything you do with a table after it has been created:
@@ -36,7 +39,7 @@ import { AreaModelIf } from './data/tablemodel/areamodel/area-model.if.js';
36
39
  * | export | {@link copyToClipboard}, {@link downloadExcel} |
37
40
  * | change data | {@link updateCells}, {@link setRows}, {@link addRows}, {@link updateRows}, {@link removeRows} |
38
41
  * | redraw | {@link repaint} (same row count), {@link repaintHard} (row count or heights changed) |
39
- * | columns | {@link autoResizeColumns}, {@link setColumnWidth}, {@link recalcColumnWidths} |
42
+ * | columns | {@link autoResizeColumns}, {@link setColumnWidth}, {@link recalcColumnWidths}, {@link getColumnIndex} |
40
43
  * | tree | {@link expandAll}, {@link collapseAll}, {@link setRowExpanded} |
41
44
  * | state | {@link getState}, {@link applyState}, {@link resetState} (with {@link TableOptionsIf.autoRestoreOptions}) |
42
45
  * | lifecycle | {@link destroy} |
@@ -390,6 +393,9 @@ export declare class TableApi {
390
393
  * Repainting the table ensures that all visible cells, rows, and styling reflect the
391
394
  * current state of the underlying data model and configuration settings.
392
395
  *
396
+ * Since 1.1.94 it also drops cached totals ({@link AreaModelIf.invalidateDerivedValues}, e.g. of a footer from
397
+ * `footerAggregates`), so they are computed again from the changed rows. Scrolling never does that.
398
+ *
393
399
  * @example
394
400
  * // Update data and repaint the table
395
401
  * const tableApi = new TableApi(tableScope);
@@ -805,6 +811,25 @@ export declare class TableApi {
805
811
  * tableApi.downloadExcel('quarterly-data.xlsx');
806
812
  */
807
813
  downloadExcel(fileName?: string, author?: string): Promise<void>;
814
+ /** The value of a cell for the Excel export – the shown number in a row number column (body; footer empty). */
815
+ private getExportValue;
816
+ /**
817
+ * The index of the column that shows a property – `-1` if there is none.
818
+ *
819
+ * Column indices count all columns, also a {@link RowNumberColumnDef} or {@link CheckboxColumnDef} in front:
820
+ * with row numbers (`rowNumbersVisible: true`) every data column has an index one higher. Get the index by the
821
+ * property instead of writing numbers into your code.
822
+ *
823
+ * @param {string} property - the property of the column definition, e.g. `"total"`
824
+ * @returns {number} the column index (fixed columns included) or -1
825
+ *
826
+ * @example
827
+ * const totalColumn = tableApi.getColumnIndex("total");
828
+ * tableApi.scrollToIndex(totalColumn, 0);
829
+ *
830
+ * @since 1.1.93
831
+ */
832
+ getColumnIndex(property: string): number;
808
833
  /**
809
834
  * Returns the TableScope instance associated with this TableApi.
810
835
  *
@@ -866,6 +891,28 @@ export declare class TableApi {
866
891
  * });
867
892
  */
868
893
  getSelectionModel(): SelectionModelIf | undefined;
894
+ /**
895
+ * Count, sum, average, minimum and maximum of the selected body cells – for a status bar like in a spreadsheet.
896
+ * Counted are the selected cells of the visible data columns; the numbers are the cell values of type `number`.
897
+ * Above {@link SelectionAggregator.maxCells} cells (default 1,000,000) nothing is computed (`capped: true`).
898
+ * Without a selection all values are 0 / `undefined`.
899
+ *
900
+ * @returns {SelectionAggregatesIf} `{ count, numericCount, sum, avg, min, max, capped }`
901
+ *
902
+ * @example
903
+ * // a status bar in plain HTML under the table
904
+ * const statusBar = document.querySelector<HTMLDivElement>("#status")!;
905
+ * const listener = new EventAdapter();
906
+ * listener.onSelectionChanged = () => {
907
+ * const a = tableApi.getSelectionAggregates();
908
+ * statusBar.textContent = a.capped ? "Selection too large"
909
+ * : a.numericCount ? `Count ${a.count} · Sum ${formatAggregateValue(a.sum)} · Average ${formatAggregateValue(a.avg)}`
910
+ * : "";
911
+ * };
912
+ *
913
+ * @since 1.1.94
914
+ */
915
+ getSelectionAggregates(): SelectionAggregatesIf;
869
916
  /**
870
917
  * Automatically resizes all columns to fit their content.
871
918
  *
@@ -1186,6 +1233,70 @@ export declare class TableApi {
1186
1233
  * tableApi.setRowExpanded(0, true); // expand the first row
1187
1234
  */
1188
1235
  setRowExpanded(rowIndex: number, expanded: boolean): boolean;
1236
+ /**
1237
+ * Row grouping ({@link RowGroupFactory}): groups the rows by other levels – without a new table model (a new model
1238
+ * would rebuild the table in every framework wrapper). Groups whose path stays keep their expanded state; filter,
1239
+ * sorting and checked rows stay; the columns of the grouped properties are hidden (the previously grouped ones come
1240
+ * back) and the header of the group column follows. An empty list shows the rows without groups.
1241
+ *
1242
+ * @param {RowGroupField[]} groupBy - the new levels, top first: property paths, functions or {@link RowGroupFieldIf}
1243
+ * @returns {boolean} false if the body is no row grouping
1244
+ *
1245
+ * @example
1246
+ * // a select with "region", "produkt", "region,produkt"
1247
+ * select.addEventListener("change", () => tableApi.setRowGroupBy(select.value.split(",")));
1248
+ *
1249
+ * @example
1250
+ * tableApi.setRowGroupBy([]); // flat again (with the total row)
1251
+ *
1252
+ * @since 1.1.94
1253
+ */
1254
+ setRowGroupBy(groupBy: RowGroupField[]): boolean;
1255
+ /**
1256
+ * Row grouping: the current levels.
1257
+ *
1258
+ * @returns {RowGroupField[] | undefined} the levels, undefined if the body is no row grouping
1259
+ *
1260
+ * @example
1261
+ * const levels = tableApi.getRowGroupBy(); // ["region", "produkt"]
1262
+ *
1263
+ * @since 1.1.94
1264
+ */
1265
+ getRowGroupBy(): RowGroupField[] | undefined;
1266
+ /**
1267
+ * Pivot table ({@link PivotFactory}): pivots again – other row fields, column fields or values, or new rows –
1268
+ * without a new table model (a new model would rebuild the table in every framework wrapper). The model gets new
1269
+ * columns, header and totals; rows whose path stays keep their expanded state, the filter stays, column widths of
1270
+ * columns that stay are kept, so are columns hidden with `setColumnVisible`. Sorting, selection and focus are reset
1271
+ * (the columns are different). An invalid configuration throws and changes nothing.
1272
+ *
1273
+ * @param {Partial<PivotConfigIf>} changes - the changed parts, e.g. `{ columnFields: ["jahr"] }`; `{}` = pivot the
1274
+ * current rows again (e.g. after new keys)
1275
+ * @param {any[]} [rows] - new source rows (default: the current ones)
1276
+ * @returns {boolean} false if the table model is no pivot table
1277
+ *
1278
+ * @example
1279
+ * // a select with the column field
1280
+ * select.addEventListener("change", () => tableApi.setPivotConfig({ columnFields: [select.value] }));
1281
+ *
1282
+ * @example
1283
+ * tableApi.setPivotConfig({ values: [{ value: "umsatz", aggregator: "avg" }] }); // averages instead of sums
1284
+ * tableApi.setPivotConfig({}, await loadSales()); // new data
1285
+ *
1286
+ * @since 1.1.94
1287
+ */
1288
+ setPivotConfig(changes: Partial<PivotConfigIf>, rows?: any[]): boolean;
1289
+ /**
1290
+ * Pivot table: the current configuration.
1291
+ *
1292
+ * @returns {PivotConfigIf | undefined} a copy, undefined if the table model is no pivot table
1293
+ *
1294
+ * @example
1295
+ * const columnFields = tableApi.getPivotConfig()?.columnFields; // ["monat"]
1296
+ *
1297
+ * @since 1.1.94
1298
+ */
1299
+ getPivotConfig(): PivotConfigIf | undefined;
1189
1300
  /**
1190
1301
  * Sorts the table data using a custom comparison function.
1191
1302
  *
@@ -22,6 +22,8 @@ import { OnActionTriggeredIf } from './action/on-action-triggered.if.js';
22
22
  import { ActionId } from './action/action-id.type.js';
23
23
  import { ShortcutService } from './action/shortcut.service.js';
24
24
  import { TreeRowIf } from './data/common/tree-row-if.js';
25
+ import { PivotConfigIf } from './pivot/pivot-config.if.js';
26
+ import { RowGroupField } from './rowgroup/row-group-field.type.js';
25
27
  import { LicenseManager } from './license-manager.js';
26
28
  import { SelectionModel } from './selection/selection-model.js';
27
29
  import { CopyServiceIf } from './service/copy-service.if.js';
@@ -329,6 +331,23 @@ export declare class TableScope extends RenderScope implements OnActionTriggered
329
331
  * @returns {boolean} false if the body is no tree or the state was already set
330
332
  */
331
333
  setTreeRowExpanded(row: TreeRowIf<any>, expanded: boolean): boolean;
334
+ /**
335
+ * Groups the rows of a row grouping by other levels (see {@link TableApi.setRowGroupBy}).
336
+ *
337
+ * @param {RowGroupField[]} groupBy - the new levels, top first
338
+ * @returns {boolean} false if the body is no row grouping
339
+ */
340
+ setRowGroupBy(groupBy: RowGroupField[]): boolean;
341
+ /**
342
+ * Pivots a pivot table again (see {@link TableApi.setPivotConfig}): new columns, header and totals in the same model,
343
+ * then the layout of the table is built again. Sorting and selection are reset (the columns are different).
344
+ *
345
+ * @param {Partial<PivotConfigIf>} changes - the changed parts of the configuration
346
+ * @param {unknown[]} [rows] - new source rows
347
+ * @returns {boolean} false if the table model is no pivot table
348
+ * @since 1.1.94
349
+ */
350
+ setPivotConfig(changes: Partial<PivotConfigIf>, rows?: unknown[]): boolean;
332
351
  /**
333
352
  * Toggles the checkbox state of a specific row in a table.
334
353
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guiexpert/table",
3
- "version": "1.1.92",
3
+ "version": "1.1.94",
4
4
  "license": "MIT",
5
5
  "author": "Dr. Marc Kronberg <info@gui.expert> (https://gui.expert)",
6
6
  "repository": {
@@ -73,6 +73,7 @@
73
73
  "test:watch": "vitest --project unit",
74
74
  "test:coverage": "vitest run --coverage",
75
75
  "test:types": "tsc -p tsconfig.spec.json --noEmit",
76
- "npm-pub": "pnpm publish --no-git-checks --access public"
76
+ "npm-pub": "pnpm publish --no-git-checks --access public",
77
+ "bench": "vitest run --config bench/vitest.bench.config.ts"
77
78
  }
78
79
  }