gm-datagrid 0.1.19 → 0.1.21
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 +113 -19
- package/dist/features/useAggregation.d.ts +12 -1
- package/dist/gm-datagrid.js +6943 -6590
- package/dist/gm-datagrid.umd.cjs +34 -35
- package/dist/lib/i18n.d.ts +28 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
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
|
-
-
|
|
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 (even when collapsed)
|
|
10
11
|
- 🔢 **Aggregation footer row** — `sum`, `avg`, `min`, `max`, `size` per column; MUI DataGrid Premium compatible `aggregationModel` API
|
|
11
12
|
- 📅 Date filter operators — is / is not / is after / is before / is empty / is not empty
|
|
12
13
|
- 📥 **Multi-format export** — toolbar picker for `xlsx` (styled, freeze pane, zebra striping via ExcelJS), `csv`, `txt`, `json`
|
|
@@ -114,6 +115,12 @@ Control which toolbar actions and column interactions are available without touc
|
|
|
114
115
|
| `sortableColumns` | `string[]` | — | Only these fields respond to header click-to-sort. Overrides per-column `sortable` |
|
|
115
116
|
| `groupable` | `boolean` | `false` | Show / hide the group-by picker in the toolbar |
|
|
116
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` |
|
|
117
124
|
|
|
118
125
|
**Example — read-only reporting grid with restricted export:**
|
|
119
126
|
|
|
@@ -152,6 +159,8 @@ interface ColumnDef {
|
|
|
152
159
|
filterable?: boolean // include in filter panel
|
|
153
160
|
editable?: boolean // enable inline cell editing
|
|
154
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
|
|
155
164
|
renderCell?: (params: CellRenderParams) => ReactNode // custom renderer
|
|
156
165
|
valueGetter?: (row: Row) => unknown // transform raw value before render
|
|
157
166
|
valueFormatter?: (value: unknown) => string // format to display string
|
|
@@ -577,10 +586,10 @@ const [aggModel, setAggModel] = useState({ total: 'sum' });
|
|
|
577
586
|
### Per-column control
|
|
578
587
|
|
|
579
588
|
```tsx
|
|
580
|
-
//
|
|
589
|
+
// Exclude a column from the footer and picker entirely
|
|
581
590
|
{ field: 'code', type: ColumnDataTypesEnum.CODE, aggregable: false }
|
|
582
591
|
|
|
583
|
-
// Restrict which functions
|
|
592
|
+
// Restrict which functions appear in the column's picker
|
|
584
593
|
{ field: 'price', type: ColumnDataTypesEnum.PRICE, availableAggregationFunctions: ['avg', 'min', 'max'] }
|
|
585
594
|
```
|
|
586
595
|
|
|
@@ -594,14 +603,38 @@ const [aggModel, setAggModel] = useState({ total: 'sum' });
|
|
|
594
603
|
| `max` | max | Largest value |
|
|
595
604
|
| `size` | # | Count of non-null cells |
|
|
596
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
|
+
|
|
597
630
|
### Aggregation props
|
|
598
631
|
|
|
599
632
|
| Prop | Type | Default | Description |
|
|
600
633
|
|---|---|---|---|
|
|
601
|
-
| `aggregable` | `boolean` | `false` | Enable the footer row |
|
|
634
|
+
| `aggregable` | `boolean` | `false` | Enable the aggregation footer row and group sub-rows |
|
|
602
635
|
| `aggregationModel` | `AggregationModel` | — | Controlled `{ field: fn }` map |
|
|
603
|
-
| `onAggregationModelChange` | `(model) => void` | — |
|
|
604
|
-
| `initialState.aggregation.model` | `AggregationModel` | — | Uncontrolled seed |
|
|
636
|
+
| `onAggregationModelChange` | `(model) => void` | — | Fired when the model changes (picker or programmatic) |
|
|
637
|
+
| `initialState.aggregation.model` | `AggregationModel` | — | Uncontrolled seed — mirrors MUI DataGrid Premium `initialState` |
|
|
605
638
|
|
|
606
639
|
---
|
|
607
640
|
|
|
@@ -619,6 +652,9 @@ import type {
|
|
|
619
652
|
CellRenderParams,
|
|
620
653
|
CellEditParams,
|
|
621
654
|
ExportFormat,
|
|
655
|
+
AggregationFunction,
|
|
656
|
+
AggregationModel,
|
|
657
|
+
AggregationResults,
|
|
622
658
|
FilterGroup,
|
|
623
659
|
FilterCellValue,
|
|
624
660
|
DateFilterValue,
|
|
@@ -638,12 +674,6 @@ import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagri
|
|
|
638
674
|
|
|
639
675
|
## Editing
|
|
640
676
|
|
|
641
|
-
### Feature flags
|
|
642
|
-
|
|
643
|
-
| Prop | Type | Default | Description |
|
|
644
|
-
|---|---|---|---|
|
|
645
|
-
| `editable` | `boolean` | `false` | Enable / disable inline editing globally |
|
|
646
|
-
| `editableColumns` | `string[]` | — | Only these fields are editable (overrides per-column `editable` flag) |
|
|
647
677
|
|
|
648
678
|
### Per-column editability
|
|
649
679
|
|
|
@@ -744,26 +774,61 @@ Need a label that doesn't match either locale, or want to override a single stri
|
|
|
744
774
|
```tsx
|
|
745
775
|
import type { GridLabels } from 'gm-datagrid'
|
|
746
776
|
|
|
747
|
-
const myLabels: GridLabels = {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
777
|
+
const myLabels: Partial<GridLabels> = {
|
|
778
|
+
// Toolbar / filter
|
|
779
|
+
search: 'Rechercher…',
|
|
780
|
+
filterBy: 'Filtrer par colonne',
|
|
781
|
+
hideFilters: 'Masquer les filtres',
|
|
751
782
|
clearFilters: 'Effacer les filtres',
|
|
752
783
|
all: 'Tous',
|
|
753
784
|
yes: 'Oui',
|
|
754
|
-
no:
|
|
785
|
+
no: 'Non',
|
|
755
786
|
min: 'Min',
|
|
756
787
|
max: 'Max',
|
|
757
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
|
|
758
823
|
dateOps: {
|
|
759
824
|
equals: 'est',
|
|
760
|
-
not:
|
|
825
|
+
not: "n'est pas",
|
|
761
826
|
gt: 'est après',
|
|
762
827
|
gte: 'est le ou après',
|
|
763
828
|
lt: 'est avant',
|
|
764
829
|
lte: 'est le ou avant',
|
|
765
830
|
isNull: 'est vide',
|
|
766
|
-
isNotNull:
|
|
831
|
+
isNotNull: "n'est pas vide",
|
|
767
832
|
},
|
|
768
833
|
}
|
|
769
834
|
|
|
@@ -772,6 +837,35 @@ const myLabels: GridLabels = {
|
|
|
772
837
|
|
|
773
838
|
All fields are optional — omit any key to fall back to the active `locale`.
|
|
774
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
|
+
|
|
775
869
|
---
|
|
776
870
|
|
|
777
871
|
## Changelog
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { AggregationFunction, AggregationModel, AggregationResults, ColumnDef } from '../types';
|
|
2
|
+
import { AggregationFunction, AggregationModel, AggregationResults, ColumnDef, Row } from '../types';
|
|
3
3
|
interface UseAggregationProps {
|
|
4
4
|
/** Grid root engine ref (same one used by useExport). */
|
|
5
5
|
engineRef: React.RefObject<unknown>;
|
|
@@ -20,4 +20,15 @@ interface UseAggregationProps {
|
|
|
20
20
|
export declare function useAggregation({ engineRef, columns, aggregationModel, enabled, }: UseAggregationProps): AggregationResults;
|
|
21
21
|
/** Human-readable label for an aggregation function (used in footer cells). */
|
|
22
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>;
|
|
23
34
|
export {};
|