gm-datagrid 0.1.18 → 0.1.19

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
@@ -7,6 +7,7 @@ Enterprise-grade, Excel-like data grid for React — powered by a **Rust/WebAsse
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
+ - 🔢 **Aggregation footer row** — `sum`, `avg`, `min`, `max`, `size` per column; MUI DataGrid Premium compatible `aggregationModel` API
10
11
  - 📅 Date filter operators — is / is not / is after / is before / is empty / is not empty
11
12
  - 📥 **Multi-format export** — toolbar picker for `xlsx` (styled, freeze pane, zebra striping via ExcelJS), `csv`, `txt`, `json`
12
13
  - 🌐 Built-in **i18n** — `locale="es"` / `locale="en"` with full label overrides
@@ -533,6 +534,77 @@ Set `calculateSubTotal: true` on any numeric column to display a live running su
533
534
 
534
535
  ---
535
536
 
537
+ ## Aggregation
538
+
539
+ Show a sticky footer row with computed aggregate values per column. Compatible with **MUI DataGrid Premium**'s `aggregationModel` API.
540
+
541
+ > **Feature flag** — disabled by default. Set `aggregable` to opt in.
542
+
543
+ ### Basic usage
544
+
545
+ ```tsx
546
+ <GMDatagrid
547
+ aggregable // enable the feature
548
+ aggregationModel={{ total: 'sum', price: 'avg', id: 'size' }}
549
+ columns={columns}
550
+ sourceApi={fetchData}
551
+ />
552
+ ```
553
+
554
+ ### Controlled model with change callback
555
+
556
+ ```tsx
557
+ const [aggModel, setAggModel] = useState({ total: 'sum' });
558
+
559
+ <GMDatagrid
560
+ aggregable
561
+ aggregationModel={aggModel}
562
+ onAggregationModelChange={setAggModel}
563
+ ...
564
+ />
565
+ ```
566
+
567
+ ### Uncontrolled initial state (MUI-compatible)
568
+
569
+ ```tsx
570
+ <GMDatagrid
571
+ aggregable
572
+ initialState={{ aggregation: { model: { total: 'sum', price: 'avg' } } }}
573
+ ...
574
+ />
575
+ ```
576
+
577
+ ### Per-column control
578
+
579
+ ```tsx
580
+ // Prevent a column from being aggregated
581
+ { field: 'code', type: ColumnDataTypesEnum.CODE, aggregable: false }
582
+
583
+ // Restrict which functions are offered in the column menu (future picker)
584
+ { field: 'price', type: ColumnDataTypesEnum.PRICE, availableAggregationFunctions: ['avg', 'min', 'max'] }
585
+ ```
586
+
587
+ ### Built-in aggregation functions
588
+
589
+ | Function | Symbol | Description |
590
+ |---|---|---|
591
+ | `sum` | Σ | Sum of all non-null values |
592
+ | `avg` | x̄ | Arithmetic mean of non-null values |
593
+ | `min` | min | Smallest value |
594
+ | `max` | max | Largest value |
595
+ | `size` | # | Count of non-null cells |
596
+
597
+ ### Aggregation props
598
+
599
+ | Prop | Type | Default | Description |
600
+ |---|---|---|---|
601
+ | `aggregable` | `boolean` | `false` | Enable the footer row |
602
+ | `aggregationModel` | `AggregationModel` | — | Controlled `{ field: fn }` map |
603
+ | `onAggregationModelChange` | `(model) => void` | — | Change callback |
604
+ | `initialState.aggregation.model` | `AggregationModel` | — | Uncontrolled seed |
605
+
606
+ ---
607
+
536
608
  ## TypeScript
537
609
 
538
610
  All types are exported from the package root:
@@ -0,0 +1,23 @@
1
+ import { default as React } from 'react';
2
+ import { AggregationFunction, AggregationModel, AggregationResults, ColumnDef } 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
+ export {};