gm-datagrid 0.1.22 → 0.1.24

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
@@ -88,6 +88,10 @@ export default function ProductsPage() {
88
88
  | `onRowDetail` | `(row) => void` | — | Called when the user opens a row detail (double-click or menu action) |
89
89
  | `checkboxSelection` | `boolean` | `false` | Prepend a checkbox column for row selection |
90
90
  | `onRowSelectionChange` | `(rows: Row[]) => void` | — | Fires on every selection change with the full array of selected rows |
91
+ | `slot` | `GridToolbarSlots` | — | Toolbar components: `bulkAction`, `creator`, `synchronizer`, `actions` (see `docs/TOOLBAR_SLOTS.md`) |
92
+ | `slotProps` | `GridToolbarSlotProps` | — | Props merged into each slot component |
93
+ | `statusSwitch` | `StatusSwitchConfig` | — | Grid defaults for inline STATUS toggles (see `docs/STATUS_SWITCH.md`) |
94
+ | `autoCheckboxSelection` | `boolean` | `true` | Enable checkboxes when `slot.bulkAction` is set |
91
95
  | `locale` | `'es' \| 'en'` | `'es'` | Built-in UI language. See [Internationalisation](#internationalisation-locale) |
92
96
 
93
97
  ### Pagination props
@@ -158,7 +162,7 @@ interface ColumnDef {
158
162
  sortable?: boolean // enable header click to sort
159
163
  filterable?: boolean // include in filter panel
160
164
  editable?: boolean // enable inline cell editing
161
- calculateSubTotal?: boolean // show running sum in header
165
+ calculateSubTotal?: boolean // show live aggregate in header; default fn chosen by column type
162
166
  aggregable?: boolean // set false to exclude from aggregation footer
163
167
  availableAggregationFunctions?: AggregationFunction[] // restrict fn picker per column
164
168
  renderCell?: (params: CellRenderParams) => ReactNode // custom renderer
@@ -535,10 +539,28 @@ The generated `.xlsx` file includes:
535
539
 
536
540
  ## Subtotals
537
541
 
538
- Set `calculateSubTotal: true` on any numeric column to display a live running sum in the column header. The subtotal updates as filters change.
542
+ 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:
543
+
544
+ | Column type | Default function |
545
+ |---|---|
546
+ | `number`, `price`, `total`, `int`, `discount`, `percent`, `tax`, `margin` | `sum` |
547
+ | `date`, `dateTime` | `count-distinct` |
548
+ | `boolean` / field named `active` | `count-true` |
549
+ | `status`, `labels` | `count-distinct` |
550
+ | `string`, `text`, all others | `count` |
551
+
552
+ ```tsx
553
+ { field: 'amount', type: ColumnDataTypesEnum.TOTAL, calculateSubTotal: true } // → sum
554
+ { field: 'date', type: ColumnDataTypesEnum.DATE, calculateSubTotal: true } // → count-distinct
555
+ { field: 'active', type: ColumnDataTypesEnum.STRING, calculateSubTotal: true } // → count-true
556
+ { field: 'status', type: ColumnDataTypesEnum.STATUS, calculateSubTotal: true } // → count-distinct
557
+ ```
558
+
559
+ You can still override the function or restrict which functions appear in the picker:
539
560
 
540
561
  ```tsx
541
- { field: 'amount', type: ColumnDataTypesEnum.TOTAL, calculateSubTotal: true }
562
+ { field: 'price', type: ColumnDataTypesEnum.PRICE, calculateSubTotal: true,
563
+ availableAggregationFunctions: ['avg', 'min', 'max'] }
542
564
  ```
543
565
 
544
566
  ---
@@ -597,15 +619,19 @@ const [aggModel, setAggModel] = useState({ total: 'sum' });
597
619
 
598
620
  | Function | Symbol | Description |
599
621
  |---|---|---|
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 |
622
+ | `sum` | Σ | Sum of all non-null values |
623
+ | `avg` | x̄ | Arithmetic mean of non-null values |
624
+ | `min` | min | Smallest value (lexicographic for strings/dates) |
625
+ | `max` | max | Largest value (lexicographic for strings/dates) |
626
+ | `size` | # | Count of non-null cells |
627
+ | `count` | # | Count of non-null cells (alias for `size`) |
628
+ | `count-distinct` | ≠# | Count of unique non-null values |
629
+ | `count-true` | ✓ | Count of truthy / `"true"` / `true` values |
630
+ | `count-false` | ✗ | Count of falsy / `"false"` / `false` values |
605
631
 
606
632
  ### Interactive function picker
607
633
 
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.
634
+ 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
635
 
610
636
  ### Group aggregation sub-rows
611
637
 
@@ -1,16 +1,18 @@
1
1
  import { default as React } from 'react';
2
- import { ColumnDef } from '../types';
2
+ import { ColumnDef, EditMode } from '../types';
3
3
  interface EditCellProps {
4
4
  rowId: string;
5
5
  field: string;
6
6
  column: ColumnDef;
7
7
  editValue: string;
8
8
  onEditValueChange: (v: string) => void;
9
- onStopEditing: (save: boolean) => Promise<void>;
9
+ onStopEditing: (save: boolean) => Promise<void> | void;
10
+ editMode?: EditMode;
11
+ autoFocus?: boolean;
10
12
  }
11
13
  /**
12
14
  * Inline edit cell — renders an <input> or <select> depending on column type.
13
- * Controlled by the parent via editValue/onEditValueChange.
15
+ * Adapts blur and key behavior based on editMode ('cell' | 'row' | 'complete').
14
16
  */
15
17
  declare const EditCell: React.NamedExoticComponent<EditCellProps>;
16
18
  export default EditCell;
@@ -0,0 +1,14 @@
1
+ import { default as React } from 'react';
2
+ import { Row, StatusSwitchConfig } from '../types';
3
+ export interface RecordStatusSwitchCellProps extends StatusSwitchConfig {
4
+ row: Row;
5
+ value?: string | null;
6
+ statusField?: string;
7
+ }
8
+ /**
9
+ * Agnostic inline A/I (or custom active/inactive) toggle for STATUS columns.
10
+ */
11
+ declare const RecordStatusSwitchCell: React.NamedExoticComponent<RecordStatusSwitchCellProps & {
12
+ apiContext?: Record<string, unknown>;
13
+ }>;
14
+ export default RecordStatusSwitchCell;
@@ -0,0 +1,5 @@
1
+ import { ColumnDef, StatusSwitchConfig } from '../types';
2
+ /**
3
+ * Merges grid-level defaults with per-column `statusSwitch` config.
4
+ */
5
+ export declare function resolveColumnStatusSwitchConfig(column: ColumnDef, gridStatusSwitch?: StatusSwitchConfig): StatusSwitchConfig | null;
@@ -0,0 +1,5 @@
1
+ import { ColumnDef, StatusSwitchConfig } from '../types';
2
+ /**
3
+ * Attaches status-switch renderers to STATUS columns when configured.
4
+ */
5
+ export declare function useResolvedColumns(columns: ColumnDef[], gridStatusSwitch?: StatusSwitchConfig): ColumnDef[];
@@ -28,6 +28,11 @@ interface GridContextValue extends DataSetState {
28
28
  isSomeSelected: boolean;
29
29
  textSearch: string;
30
30
  setTextSearch: (v: string) => void;
31
+ /** All rows in the current dataset (alias for rows). */
32
+ data: Row[];
33
+ getRows: () => Row[];
34
+ getSelectedRows: () => Row[];
35
+ selectedCount: number;
31
36
  }
32
37
  interface GridProviderProps {
33
38
  dataset: DataSetState;