gm-datagrid 0.1.18 → 0.1.20

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 CHANGED
@@ -3,10 +3,12 @@
3
3
  Enterprise-grade, Excel-like data grid for React — powered by a **Rust/WebAssembly** core engine.
4
4
 
5
5
  - ⚡ Handles **100 000+ rows** at 60 FPS with canvas-free virtualization
6
- - 🦀 Sorting, filtering, aggregation and Excel export run inside **Rust/Wasm** — off the main thread
6
+ - 🦥 Sorting, filtering, and Excel export run inside **Rust/Wasm** — off the main thread
7
7
  - 📋 Excel-compatible clipboard (Ctrl+C / Ctrl+V TSV)
8
8
  - ✏️ Inline cell editing with async validation and automatic revert on error
9
9
  - 📊 Column subtotals updated live as filters change
10
+ - 🔢 **Inline Group Aggregations** — column-aligned aggregates visible directly in group headers
11
+ - 🔢 **Aggregation footer row** — `sum`, `avg`, `min`, `max`, `size` per column; MUI DataGrid Premium compatible `aggregationModel` API
10
12
  - 📅 Date filter operators — is / is not / is after / is before / is empty / is not empty
11
13
  - 📥 **Multi-format export** — toolbar picker for `xlsx` (styled, freeze pane, zebra striping via ExcelJS), `csv`, `txt`, `json`
12
14
  - 🌐 Built-in **i18n** — `locale="es"` / `locale="en"` with full label overrides
@@ -113,6 +115,12 @@ Control which toolbar actions and column interactions are available without touc
113
115
  | `sortableColumns` | `string[]` | — | Only these fields respond to header click-to-sort. Overrides per-column `sortable` |
114
116
  | `groupable` | `boolean` | `false` | Show / hide the group-by picker in the toolbar |
115
117
  | `groupableColumns` | `string[]` | — | Fields offered in the group-by picker. Falls back to all columns when omitted |
118
+ | `editable` | `boolean` | `false` | Enable / disable inline editing globally |
119
+ | `editableColumns` | `string[]` | — | Only these fields are editable (overrides per-column `editable` flag) |
120
+ | `aggregable` | `boolean` | `false` | Enable the **aggregation footer row**. Off by default — zero overhead when unused |
121
+ | `aggregationModel` | `AggregationModel` | — | Controlled `{ field: fn }` map (see [Aggregation](#aggregation)) |
122
+ | `onAggregationModelChange` | `(model: AggregationModel) => void` | — | Fired when the aggregation model changes |
123
+ | `initialState` | `{ aggregation?: { model: AggregationModel } }` | — | Uncontrolled seed — mirrors MUI DataGrid Premium `initialState.aggregation.model` |
116
124
 
117
125
  **Example — read-only reporting grid with restricted export:**
118
126
 
@@ -151,6 +159,8 @@ interface ColumnDef {
151
159
  filterable?: boolean // include in filter panel
152
160
  editable?: boolean // enable inline cell editing
153
161
  calculateSubTotal?: boolean // show running sum in header
162
+ aggregable?: boolean // set false to exclude from aggregation footer
163
+ availableAggregationFunctions?: AggregationFunction[] // restrict fn picker per column
154
164
  renderCell?: (params: CellRenderParams) => ReactNode // custom renderer
155
165
  valueGetter?: (row: Row) => unknown // transform raw value before render
156
166
  valueFormatter?: (value: unknown) => string // format to display string
@@ -533,6 +543,101 @@ Set `calculateSubTotal: true` on any numeric column to display a live running su
533
543
 
534
544
  ---
535
545
 
546
+ ## Aggregation
547
+
548
+ Show a sticky footer row with computed aggregate values per column. Compatible with **MUI DataGrid Premium**'s `aggregationModel` API.
549
+
550
+ > **Feature flag** — disabled by default. Set `aggregable` to opt in.
551
+
552
+ ### Basic usage
553
+
554
+ ```tsx
555
+ <GMDatagrid
556
+ aggregable // enable the feature
557
+ aggregationModel={{ total: 'sum', price: 'avg', id: 'size' }}
558
+ columns={columns}
559
+ sourceApi={fetchData}
560
+ />
561
+ ```
562
+
563
+ ### Controlled model with change callback
564
+
565
+ ```tsx
566
+ const [aggModel, setAggModel] = useState({ total: 'sum' });
567
+
568
+ <GMDatagrid
569
+ aggregable
570
+ aggregationModel={aggModel}
571
+ onAggregationModelChange={setAggModel}
572
+ ...
573
+ />
574
+ ```
575
+
576
+ ### Uncontrolled initial state (MUI-compatible)
577
+
578
+ ```tsx
579
+ <GMDatagrid
580
+ aggregable
581
+ initialState={{ aggregation: { model: { total: 'sum', price: 'avg' } } }}
582
+ ...
583
+ />
584
+ ```
585
+
586
+ ### Per-column control
587
+
588
+ ```tsx
589
+ // Exclude a column from the footer and picker entirely
590
+ { field: 'code', type: ColumnDataTypesEnum.CODE, aggregable: false }
591
+
592
+ // Restrict which functions appear in the column's picker
593
+ { field: 'price', type: ColumnDataTypesEnum.PRICE, availableAggregationFunctions: ['avg', 'min', 'max'] }
594
+ ```
595
+
596
+ ### Built-in aggregation functions
597
+
598
+ | Function | Symbol | Description |
599
+ |---|---|---|
600
+ | `sum` | Σ | Sum of all non-null values |
601
+ | `avg` | x̄ | Arithmetic mean of non-null values |
602
+ | `min` | min | Smallest value |
603
+ | `max` | max | Largest value |
604
+ | `size` | # | Count of non-null cells |
605
+
606
+ ### Interactive function picker
607
+
608
+ When `aggregable` is enabled each aggregable column header shows a small pill with the active function symbol (`Σ`, `x̄`, `min`, `max`, `#`), or `Σ…` when no function is set. Clicking the pill opens a **Popover** listing the available functions (all five, or the `availableAggregationFunctions` subset). Selecting a function updates the model and fires `onAggregationModelChange`. A **Remove aggregation** option clears that column from the model.
609
+
610
+ ### Group aggregation sub-rows
611
+
612
+ When both `aggregable` and `groupable` are enabled, every **expanded group** shows a compact sub-row (blue left border, muted background) with per-group aggregate values aligned to their columns.
613
+
614
+ ```tsx
615
+ <GMDatagrid
616
+ aggregable
617
+ groupable
618
+ aggregationModel={{ total: 'sum', price: 'avg' }}
619
+ onAggregationModelChange={setAggModel}
620
+ columns={[
621
+ { field: 'customer', type: ColumnDataTypesEnum.STRING },
622
+ { field: 'total', type: ColumnDataTypesEnum.TOTAL },
623
+ { field: 'price', type: ColumnDataTypesEnum.PRICE, availableAggregationFunctions: ['avg', 'min', 'max'] },
624
+ { field: 'code', type: ColumnDataTypesEnum.CODE, aggregable: false },
625
+ ]}
626
+ sourceApi={fetchOrders}
627
+ />
628
+ ```
629
+
630
+ ### Aggregation props
631
+
632
+ | Prop | Type | Default | Description |
633
+ |---|---|---|---|
634
+ | `aggregable` | `boolean` | `false` | Enable the aggregation footer row and group sub-rows |
635
+ | `aggregationModel` | `AggregationModel` | — | Controlled `{ field: fn }` map |
636
+ | `onAggregationModelChange` | `(model) => void` | — | Fired when the model changes (picker or programmatic) |
637
+ | `initialState.aggregation.model` | `AggregationModel` | — | Uncontrolled seed — mirrors MUI DataGrid Premium `initialState` |
638
+
639
+ ---
640
+
536
641
  ## TypeScript
537
642
 
538
643
  All types are exported from the package root:
@@ -547,6 +652,9 @@ import type {
547
652
  CellRenderParams,
548
653
  CellEditParams,
549
654
  ExportFormat,
655
+ AggregationFunction,
656
+ AggregationModel,
657
+ AggregationResults,
550
658
  FilterGroup,
551
659
  FilterCellValue,
552
660
  DateFilterValue,
@@ -566,12 +674,6 @@ import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagri
566
674
 
567
675
  ## Editing
568
676
 
569
- ### Feature flags
570
-
571
- | Prop | Type | Default | Description |
572
- |---|---|---|---|
573
- | `editable` | `boolean` | `false` | Enable / disable inline editing globally |
574
- | `editableColumns` | `string[]` | — | Only these fields are editable (overrides per-column `editable` flag) |
575
677
 
576
678
  ### Per-column editability
577
679
 
@@ -672,26 +774,61 @@ Need a label that doesn't match either locale, or want to override a single stri
672
774
  ```tsx
673
775
  import type { GridLabels } from 'gm-datagrid'
674
776
 
675
- const myLabels: GridLabels = {
676
- search: 'Rechercher…',
677
- filterBy: 'Filtrer par colonne',
678
- hideFilters: 'Masquer les filtres',
777
+ const myLabels: Partial<GridLabels> = {
778
+ // Toolbar / filter
779
+ search: 'Rechercher…',
780
+ filterBy: 'Filtrer par colonne',
781
+ hideFilters: 'Masquer les filtres',
679
782
  clearFilters: 'Effacer les filtres',
680
783
  all: 'Tous',
681
784
  yes: 'Oui',
682
- no: 'Non',
785
+ no: 'Non',
683
786
  min: 'Min',
684
787
  max: 'Max',
685
788
  noGroup: 'Sans regroupement',
789
+
790
+ // Pagination
791
+ noRows: '0 enregistrements',
792
+ rowsRange: '{from}–{to} sur {total} enregistrements',
793
+ rowsPerPage: 'Lignes par page :',
794
+ firstPage: 'Première page',
795
+ prevPage: 'Page précédente',
796
+ nextPage: 'Page suivante',
797
+ lastPage: 'Dernière page',
798
+
799
+ // Row selection
800
+ selectAll: 'Tout sélectionner',
801
+ deselectAll: 'Tout désélectionner',
802
+ selectionSingular: 'élément sélectionné',
803
+ selectionPlural: 'éléments sélectionnés',
804
+ clearSelection: 'Effacer',
805
+
806
+ // Groups
807
+ emptyGroup: '(Vide)',
808
+
809
+ // Engine error
810
+ engineError: "Impossible d'initialiser le moteur de données",
811
+
812
+ // Aggregation
813
+ aggregationFns: {
814
+ sum: 'Somme',
815
+ avg: 'Moyenne',
816
+ min: 'Minimum',
817
+ max: 'Maximum',
818
+ size: 'Nombre',
819
+ },
820
+ aggregationTooltipLabel: '{fn} : {value}',
821
+
822
+ // Date filter operators
686
823
  dateOps: {
687
824
  equals: 'est',
688
- not: 'n\'est pas',
825
+ not: "n'est pas",
689
826
  gt: 'est après',
690
827
  gte: 'est le ou après',
691
828
  lt: 'est avant',
692
829
  lte: 'est le ou avant',
693
830
  isNull: 'est vide',
694
- isNotNull: 'n\'est pas vide',
831
+ isNotNull: "n'est pas vide",
695
832
  },
696
833
  }
697
834
 
@@ -700,6 +837,35 @@ const myLabels: GridLabels = {
700
837
 
701
838
  All fields are optional — omit any key to fall back to the active `locale`.
702
839
 
840
+ ### `GridLabels` reference
841
+
842
+ | Key | `es` default | `en` default |
843
+ |---|---|---|
844
+ | `search` | `Buscar…` | `Search…` |
845
+ | `filterBy` | `Filtrar por columna` | `Filter by column` |
846
+ | `hideFilters` | `Ocultar filtros` | `Hide filters` |
847
+ | `clearFilters` | `Limpiar filtros` | `Clear filters` |
848
+ | `noRows` | `0 registros` | `0 records` |
849
+ | `rowsRange` | `{from}–{to} de {total} registros` | `{from}–{to} of {total} records` |
850
+ | `rowsPerPage` | `Filas por página:` | `Rows per page:` |
851
+ | `firstPage` | `Primera página` | `First page` |
852
+ | `prevPage` | `Página anterior` | `Previous page` |
853
+ | `nextPage` | `Página siguiente` | `Next page` |
854
+ | `lastPage` | `Última página` | `Last page` |
855
+ | `selectAll` | `Seleccionar todo` | `Select all` |
856
+ | `deselectAll` | `Deseleccionar todo` | `Deselect all` |
857
+ | `selectionSingular` | `elemento seleccionado` | `item selected` |
858
+ | `selectionPlural` | `elementos seleccionados` | `items selected` |
859
+ | `clearSelection` | `Limpiar` | `Clear` |
860
+ | `emptyGroup` | `(Sin valor)` | `(Empty)` |
861
+ | `engineError` | `No se pudo inicializar el motor de datos` | `Could not initialize the data engine` |
862
+ | `aggregationFns.sum` | `Suma` | `Sum` |
863
+ | `aggregationFns.avg` | `Promedio` | `Average` |
864
+ | `aggregationFns.min` | `Mínimo` | `Minimum` |
865
+ | `aggregationFns.max` | `Máximo` | `Maximum` |
866
+ | `aggregationFns.size` | `Cantidad` | `Count` |
867
+ | `aggregationTooltipLabel` | `{fn}: {value}` | `{fn}: {value}` |
868
+
703
869
  ---
704
870
 
705
871
  ## Changelog
@@ -0,0 +1,34 @@
1
+ import { default as React } from 'react';
2
+ import { AggregationFunction, AggregationModel, AggregationResults, ColumnDef, Row } from '../types';
3
+ interface UseAggregationProps {
4
+ /** Grid root engine ref (same one used by useExport). */
5
+ engineRef: React.RefObject<unknown>;
6
+ columns: ColumnDef[];
7
+ /** { field: 'sum' | 'avg' | ... } — only entries here produce footer cells. */
8
+ aggregationModel: AggregationModel;
9
+ /** When false the hook is a no-op. */
10
+ enabled: boolean;
11
+ }
12
+ /**
13
+ * Computes aggregated footer values from the full filtered+sorted dataset.
14
+ * Runs entirely in TypeScript using `engine.get_all_rows()` — no Rust changes needed.
15
+ *
16
+ * Compatible with MUI DataGrid Premium aggregation model:
17
+ * aggregationModel = { gross: 'sum', year: 'max' }
18
+ * → returns { gross: 50212864155, year: 2021 }
19
+ */
20
+ export declare function useAggregation({ engineRef, columns, aggregationModel, enabled, }: UseAggregationProps): AggregationResults;
21
+ /** Human-readable label for an aggregation function (used in footer cells). */
22
+ export declare function aggFnLabel(fn: AggregationFunction): string;
23
+ /**
24
+ * Computes aggregated values for each group independently.
25
+ * Uses the pre-fetched `groupRows` map (populated when aggregable is enabled).
26
+ * Returns { [groupKey]: { [field]: number | null } }
27
+ */
28
+ export declare function useGroupAggregations({ groupRows, columns, aggregationModel, enabled, }: {
29
+ groupRows: Record<string, Row[]>;
30
+ columns: ColumnDef[];
31
+ aggregationModel: AggregationModel;
32
+ enabled: boolean;
33
+ }): Record<string, AggregationResults>;
34
+ export {};