gm-datagrid 0.1.22 → 0.1.23
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 +31 -9
- package/dist/features/useAggregation.d.ts +21 -13
- package/dist/gm-datagrid.js +1663 -1593
- package/dist/gm-datagrid.umd.cjs +17 -17
- package/dist/types/index.d.ts +11 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -158,7 +158,7 @@ interface ColumnDef {
|
|
|
158
158
|
sortable?: boolean // enable header click to sort
|
|
159
159
|
filterable?: boolean // include in filter panel
|
|
160
160
|
editable?: boolean // enable inline cell editing
|
|
161
|
-
calculateSubTotal?: boolean // show
|
|
161
|
+
calculateSubTotal?: boolean // show live aggregate in header; default fn chosen by column type
|
|
162
162
|
aggregable?: boolean // set false to exclude from aggregation footer
|
|
163
163
|
availableAggregationFunctions?: AggregationFunction[] // restrict fn picker per column
|
|
164
164
|
renderCell?: (params: CellRenderParams) => ReactNode // custom renderer
|
|
@@ -535,10 +535,28 @@ The generated `.xlsx` file includes:
|
|
|
535
535
|
|
|
536
536
|
## Subtotals
|
|
537
537
|
|
|
538
|
-
Set `calculateSubTotal: true` on any
|
|
538
|
+
Set `calculateSubTotal: true` on any column to display a live aggregate in the column header. The value updates as filters change. No `aggregationModel` prop is needed — the default aggregation function is chosen automatically based on the column type:
|
|
539
|
+
|
|
540
|
+
| Column type | Default function |
|
|
541
|
+
|---|---|
|
|
542
|
+
| `number`, `price`, `total`, `int`, `discount`, `percent`, `tax`, `margin` | `sum` |
|
|
543
|
+
| `date`, `dateTime` | `count-distinct` |
|
|
544
|
+
| `boolean` / field named `active` | `count-true` |
|
|
545
|
+
| `status`, `labels` | `count-distinct` |
|
|
546
|
+
| `string`, `text`, all others | `count` |
|
|
547
|
+
|
|
548
|
+
```tsx
|
|
549
|
+
{ field: 'amount', type: ColumnDataTypesEnum.TOTAL, calculateSubTotal: true } // → sum
|
|
550
|
+
{ field: 'date', type: ColumnDataTypesEnum.DATE, calculateSubTotal: true } // → count-distinct
|
|
551
|
+
{ field: 'active', type: ColumnDataTypesEnum.STRING, calculateSubTotal: true } // → count-true
|
|
552
|
+
{ field: 'status', type: ColumnDataTypesEnum.STATUS, calculateSubTotal: true } // → count-distinct
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
You can still override the function or restrict which functions appear in the picker:
|
|
539
556
|
|
|
540
557
|
```tsx
|
|
541
|
-
{ field: '
|
|
558
|
+
{ field: 'price', type: ColumnDataTypesEnum.PRICE, calculateSubTotal: true,
|
|
559
|
+
availableAggregationFunctions: ['avg', 'min', 'max'] }
|
|
542
560
|
```
|
|
543
561
|
|
|
544
562
|
---
|
|
@@ -597,15 +615,19 @@ const [aggModel, setAggModel] = useState({ total: 'sum' });
|
|
|
597
615
|
|
|
598
616
|
| Function | Symbol | Description |
|
|
599
617
|
|---|---|---|
|
|
600
|
-
| `sum`
|
|
601
|
-
| `avg`
|
|
602
|
-
| `min`
|
|
603
|
-
| `max`
|
|
604
|
-
| `size`
|
|
618
|
+
| `sum` | Σ | Sum of all non-null values |
|
|
619
|
+
| `avg` | x̄ | Arithmetic mean of non-null values |
|
|
620
|
+
| `min` | min | Smallest value (lexicographic for strings/dates) |
|
|
621
|
+
| `max` | max | Largest value (lexicographic for strings/dates) |
|
|
622
|
+
| `size` | # | Count of non-null cells |
|
|
623
|
+
| `count` | # | Count of non-null cells (alias for `size`) |
|
|
624
|
+
| `count-distinct` | ≠# | Count of unique non-null values |
|
|
625
|
+
| `count-true` | ✓ | Count of truthy / `"true"` / `true` values |
|
|
626
|
+
| `count-false` | ✗ | Count of falsy / `"false"` / `false` values |
|
|
605
627
|
|
|
606
628
|
### Interactive function picker
|
|
607
629
|
|
|
608
|
-
|
|
630
|
+
Columns with `calculateSubTotal: true` show a small pill in the column header with the active function symbol (`Σ`, `x̄`, `min`, `max`, `#`, `≠#`, `✓`, `✗`). Clicking the pill opens a **Popover** listing the functions available for that column's type (or the `availableAggregationFunctions` override). Selecting a function updates the model and fires `onAggregationModelChange`. A **Remove aggregation** option clears the column from the model.
|
|
609
631
|
|
|
610
632
|
### Group aggregation sub-rows
|
|
611
633
|
|
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { AggregationFunction, AggregationModel, AggregationResults, ColumnDef, Row } from '../types';
|
|
3
3
|
interface UseAggregationProps {
|
|
4
|
-
/** Grid root engine ref (same one used by useExport). */
|
|
5
4
|
engineRef: React.RefObject<unknown>;
|
|
6
5
|
columns: ColumnDef[];
|
|
7
|
-
/** { field: 'sum' | 'avg' | ... } — only entries here produce footer cells. */
|
|
8
6
|
aggregationModel: AggregationModel;
|
|
9
|
-
/** When false the hook is a no-op. */
|
|
10
7
|
enabled: boolean;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* Returns the aggregation functions available for a column based on its type.
|
|
11
|
+
* Used to populate the picker and to auto-derive the initial aggregation model
|
|
12
|
+
* for columns with `calculateSubTotal: true`.
|
|
15
13
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* | Column type | Available functions |
|
|
15
|
+
* |--------------------------|--------------------------------------------|
|
|
16
|
+
* | numeric | sum, avg, min, max, count |
|
|
17
|
+
* | date / dateTime | min, max, count-distinct, count |
|
|
18
|
+
* | boolean / active | count-true, count-false, count |
|
|
19
|
+
* | status / labels | count-distinct, count |
|
|
20
|
+
* | string (default) | min, max, count-distinct, count |
|
|
19
21
|
*/
|
|
20
|
-
export declare function
|
|
21
|
-
/**
|
|
22
|
+
export declare function getDefaultAvailableFns(col: ColumnDef): AggregationFunction[];
|
|
23
|
+
/** Returns the best default aggregation function for a column (first of its type defaults). */
|
|
24
|
+
export declare function getDefaultAggFn(col: ColumnDef): AggregationFunction;
|
|
25
|
+
/** Short symbol shown inside the aggregation pill in the column header. */
|
|
22
26
|
export declare function aggFnLabel(fn: AggregationFunction): string;
|
|
23
27
|
/**
|
|
24
|
-
* Computes aggregated values
|
|
25
|
-
*
|
|
26
|
-
|
|
28
|
+
* Computes aggregated footer values from the full filtered+sorted dataset.
|
|
29
|
+
* Only processes columns present in `aggregationModel`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useAggregation({ engineRef, columns, aggregationModel, enabled, }: UseAggregationProps): AggregationResults;
|
|
32
|
+
/**
|
|
33
|
+
* Computes per-group aggregated values.
|
|
34
|
+
* Uses the pre-fetched `groupRows` map.
|
|
27
35
|
*/
|
|
28
36
|
export declare function useGroupAggregations({ groupRows, columns, aggregationModel, enabled, }: {
|
|
29
37
|
groupRows: Record<string, Row[]>;
|