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 +35 -9
- package/dist/cells/EditCell.d.ts +5 -3
- package/dist/cells/RecordStatusSwitchCell.d.ts +14 -0
- package/dist/cells/resolveColumnStatusSwitch.d.ts +5 -0
- package/dist/columns/useResolvedColumns.d.ts +5 -0
- package/dist/context/GridContext.d.ts +5 -0
- package/dist/core_engine-CUZl08WL.js +431 -0
- package/dist/dataset/useGMDataSet.d.ts +6 -0
- package/dist/features/useAggregation.d.ts +23 -13
- package/dist/features/useInlineEdit.d.ts +39 -17
- package/dist/gm-datagrid.js +8341 -7250
- package/dist/gm-datagrid.umd.cjs +53 -50
- package/dist/index.d.ts +4 -1
- package/dist/toolbar/GridBulkActionsHost.d.ts +12 -0
- package/dist/toolbar/GridToolbar.d.ts +5 -1
- package/dist/toolbar/GridToolbarCreator.d.ts +11 -0
- package/dist/toolbar/GridToolbarSynchronizer.d.ts +10 -0
- package/dist/toolbar/MobileToolbar.d.ts +5 -1
- package/dist/types/index.d.ts +168 -7
- package/docs/MIGRATION_LEGACY_GMGRID.md +20 -0
- package/docs/STATUS_SWITCH.md +37 -0
- package/docs/TOOLBAR_SLOTS.md +68 -0
- package/package.json +73 -71
- package/dist/core_engine-21HtFNxu.js +0 -360
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ export { GMDatagrid } from './GMDatagrid';
|
|
|
2
2
|
export { GMGridContainer } from './GMGridContainer';
|
|
3
3
|
export type { GMGridContainerRef } from './GMGridContainer';
|
|
4
4
|
export { useGMGrid } from './context/GridContext';
|
|
5
|
-
export type { GMDatagridProps, GMDatagridRef, ColumnDef, Row, CellRange, CellCoord, FilterGroup, FilterCondition, SortKey, ApiContext, DensityMode, MuiChipColor, StatusMapEntry, CellRenderParams, CellEditParams, } from './types';
|
|
5
|
+
export type { GMDatagridProps, GMDatagridRef, ColumnDef, Row, CellRange, CellCoord, FilterGroup, FilterCondition, SortKey, ApiContext, DensityMode, MuiChipColor, StatusMapEntry, CellRenderParams, CellEditParams, GridBulkActionProps, GridCreatorSlotProps, GridSynchronizerSlotProps, GridToolbarSlots, GridToolbarSlotProps, StatusSwitchConfig, StatusSwitchUpdateArgs, } from './types';
|
|
6
6
|
export { ColumnDataTypesEnum } from './types';
|
|
7
|
+
export { default as RecordStatusSwitchCell } from './cells/RecordStatusSwitchCell';
|
|
8
|
+
export { resolveColumnStatusSwitchConfig } from './cells/resolveColumnStatusSwitch';
|
|
9
|
+
export { default as GridBulkActionsHost } from './toolbar/GridBulkActionsHost';
|
|
7
10
|
export type { ExportFormat } from './types';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { GridBulkActionProps } from '../types';
|
|
3
|
+
interface GridBulkActionsHostProps {
|
|
4
|
+
component?: React.ComponentType<GridBulkActionProps>;
|
|
5
|
+
showWhenEmpty?: boolean;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Injects selected rows and grid refresh into a host-provided bulk-action component.
|
|
10
|
+
*/
|
|
11
|
+
export default function GridBulkActionsHost({ component: Component, showWhenEmpty, ...rest }: GridBulkActionsHostProps): import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { DensityMode, ExportFormat } from '../types';
|
|
2
|
+
import { DensityMode, ExportFormat, GridToolbarSlotProps, GridToolbarSlots } from '../types';
|
|
3
3
|
import { GridLabels } from '../lib/i18n';
|
|
4
4
|
interface GridToolbarProps {
|
|
5
5
|
title: string;
|
|
@@ -31,6 +31,10 @@ interface GridToolbarProps {
|
|
|
31
31
|
onClearFilters?: () => void;
|
|
32
32
|
/** UI label translations */
|
|
33
33
|
labels?: GridLabels;
|
|
34
|
+
slots?: GridToolbarSlots;
|
|
35
|
+
slotProps?: GridToolbarSlotProps;
|
|
36
|
+
selectionCount?: number;
|
|
37
|
+
onClearSelection?: () => void;
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* Desktop toolbar: title, optional quick-filter input, action buttons, subtotals row.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { GridCreatorSlotProps } from '../types';
|
|
3
|
+
interface GridToolbarCreatorProps {
|
|
4
|
+
creator?: ComponentType<GridCreatorSlotProps>;
|
|
5
|
+
creatorProps?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders a host-provided create control; the host component owns dialog UX and permissions.
|
|
9
|
+
*/
|
|
10
|
+
export default function GridToolbarCreator({ creator: Creator, creatorProps }: GridToolbarCreatorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface GridToolbarSynchronizerProps {
|
|
2
|
+
handler?: () => void | Promise<void>;
|
|
3
|
+
tooltip?: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generic toolbar sync button — runs `handler` then refreshes the grid.
|
|
8
|
+
*/
|
|
9
|
+
export default function GridToolbarSynchronizer({ handler, tooltip, disabled, }: GridToolbarSynchronizerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { DensityMode, ExportFormat } from '../types';
|
|
2
|
+
import { DensityMode, ExportFormat, GridToolbarSlotProps, GridToolbarSlots } from '../types';
|
|
3
3
|
import { GridLabels } from '../lib/i18n';
|
|
4
4
|
interface MobileToolbarProps {
|
|
5
5
|
title: string;
|
|
@@ -22,6 +22,10 @@ interface MobileToolbarProps {
|
|
|
22
22
|
onClearFilters?: () => void;
|
|
23
23
|
/** UI label translations */
|
|
24
24
|
labels?: GridLabels;
|
|
25
|
+
slots?: GridToolbarSlots;
|
|
26
|
+
slotProps?: GridToolbarSlotProps;
|
|
27
|
+
selectionCount?: number;
|
|
28
|
+
onClearSelection?: () => void;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* Collapsible mobile toolbar — same features as GridToolbar but stacked vertically.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -29,20 +29,24 @@ export type ExportFormat = 'xlsx' | 'csv' | 'txt' | 'json';
|
|
|
29
29
|
/**
|
|
30
30
|
* Built-in aggregation functions — mirrors MUI DataGrid Premium's built-in set.
|
|
31
31
|
* - `sum` — total of all numeric values
|
|
32
|
-
* - `avg`
|
|
33
|
-
* - `min`
|
|
34
|
-
* - `max`
|
|
35
|
-
* - `size`
|
|
32
|
+
* - `avg` — arithmetic mean of non-null values
|
|
33
|
+
* - `min` — smallest value (numeric or lexicographic for strings/dates)
|
|
34
|
+
* - `max` — largest value (numeric or lexicographic for strings/dates)
|
|
35
|
+
* - `size` — legacy alias for `count`
|
|
36
|
+
* - `count` — count of non-null cells
|
|
37
|
+
* - `count-distinct`— count of unique non-null values
|
|
38
|
+
* - `count-true` — count of truthy values (boolean columns)
|
|
39
|
+
* - `count-false` — count of falsy (but non-null) values (boolean columns)
|
|
36
40
|
*/
|
|
37
|
-
export type AggregationFunction = 'sum' | 'avg' | 'min' | 'max' | 'size';
|
|
41
|
+
export type AggregationFunction = 'sum' | 'avg' | 'min' | 'max' | 'size' | 'count' | 'count-distinct' | 'count-true' | 'count-false';
|
|
38
42
|
/**
|
|
39
43
|
* Aggregation model — keys are column `field` names, values are function names.
|
|
40
44
|
* Compatible with MUI DataGrid Premium `aggregationModel` prop.
|
|
41
45
|
* @example { gross: 'sum', year: 'max' }
|
|
42
46
|
*/
|
|
43
47
|
export type AggregationModel = Record<string, AggregationFunction>;
|
|
44
|
-
/** Computed aggregation results — keys are column `field` names, values are the aggregated
|
|
45
|
-
export type AggregationResults = Record<string, number | null>;
|
|
48
|
+
/** Computed aggregation results — keys are column `field` names, values are the aggregated result (number or string). */
|
|
49
|
+
export type AggregationResults = Record<string, number | string | null>;
|
|
46
50
|
export interface StatusMapEntry {
|
|
47
51
|
label: string;
|
|
48
52
|
color: MuiChipColor;
|
|
@@ -88,6 +92,71 @@ export interface ColumnDef {
|
|
|
88
92
|
valueFormatter?: (value: unknown) => string;
|
|
89
93
|
/** Mapping of raw values to chip labels/colors for `status` columns. */
|
|
90
94
|
statusMap?: Record<string, StatusMapEntry>;
|
|
95
|
+
/**
|
|
96
|
+
* Inline active/inactive toggle on STATUS columns.
|
|
97
|
+
* `true` uses grid-level `statusSwitch` defaults; object merges over grid; `false` disables.
|
|
98
|
+
*/
|
|
99
|
+
statusSwitch?: boolean | StatusSwitchConfig | false;
|
|
100
|
+
}
|
|
101
|
+
export interface GridBulkActionProps {
|
|
102
|
+
selectedRows: Row[];
|
|
103
|
+
selectedCount: number;
|
|
104
|
+
onRefresh: () => void;
|
|
105
|
+
clearSelection: () => void;
|
|
106
|
+
disabled?: boolean;
|
|
107
|
+
onAfterSave?: () => void;
|
|
108
|
+
[key: string]: unknown;
|
|
109
|
+
}
|
|
110
|
+
export interface GridCreatorSlotProps {
|
|
111
|
+
onRefresh: () => void;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
export interface GridSynchronizerSlotProps {
|
|
115
|
+
onRefresh: () => void;
|
|
116
|
+
onSync: () => void | Promise<void>;
|
|
117
|
+
[key: string]: unknown;
|
|
118
|
+
}
|
|
119
|
+
export interface GridToolbarSlots {
|
|
120
|
+
bulkAction?: React.ComponentType<GridBulkActionProps>;
|
|
121
|
+
creator?: React.ComponentType<GridCreatorSlotProps>;
|
|
122
|
+
synchronizer?: React.ComponentType<GridSynchronizerSlotProps>;
|
|
123
|
+
actions?: React.ComponentType<Record<string, unknown>>;
|
|
124
|
+
}
|
|
125
|
+
export interface GridToolbarSlotProps {
|
|
126
|
+
bulkAction?: Record<string, unknown> & {
|
|
127
|
+
showWhenEmpty?: boolean;
|
|
128
|
+
};
|
|
129
|
+
creator?: Record<string, unknown>;
|
|
130
|
+
synchronizer?: Record<string, unknown> & {
|
|
131
|
+
handler?: () => void | Promise<void>;
|
|
132
|
+
};
|
|
133
|
+
actions?: Record<string, unknown>;
|
|
134
|
+
toolbar?: Record<string, unknown>;
|
|
135
|
+
}
|
|
136
|
+
export interface StatusSwitchUpdateArgs {
|
|
137
|
+
id: string | number;
|
|
138
|
+
status: string;
|
|
139
|
+
row: Row;
|
|
140
|
+
context?: ApiContext;
|
|
141
|
+
}
|
|
142
|
+
export interface StatusSwitchConfig {
|
|
143
|
+
updateApi: (args: StatusSwitchUpdateArgs) => Promise<unknown>;
|
|
144
|
+
statusField?: string;
|
|
145
|
+
activeValue?: string;
|
|
146
|
+
inactiveValue?: string;
|
|
147
|
+
getRecordId?: (row: Row) => string | number;
|
|
148
|
+
disableWhenDeleted?: boolean;
|
|
149
|
+
deletedField?: string;
|
|
150
|
+
deletedStatus?: string;
|
|
151
|
+
canEdit?: boolean | ((row: Row) => boolean);
|
|
152
|
+
confirmBeforeUpdate?: boolean | ((row: Row, newStatus: string) => string | false);
|
|
153
|
+
successMessage?: string;
|
|
154
|
+
onNotify?: (message: string, severity: 'success' | 'error') => void;
|
|
155
|
+
onAfterUpdate?: (row: Row, newStatus: string) => void;
|
|
156
|
+
/** @default true */
|
|
157
|
+
optimistic?: boolean;
|
|
158
|
+
onRefresh?: () => void;
|
|
159
|
+
companyId?: string | number;
|
|
91
160
|
}
|
|
92
161
|
export type CellValue = string | number | boolean | null | undefined | string[];
|
|
93
162
|
export type Row = Record<string, CellValue>;
|
|
@@ -136,6 +205,8 @@ export interface ApiContext {
|
|
|
136
205
|
[key: string]: unknown;
|
|
137
206
|
}
|
|
138
207
|
export interface GMDatagridRef {
|
|
208
|
+
/** Returns all loaded rows (current dataset). */
|
|
209
|
+
getRows: () => Row[];
|
|
139
210
|
/** Returns a copy of all currently selected rows. */
|
|
140
211
|
getSelectedRows: () => Row[];
|
|
141
212
|
/** Clears the current selection. */
|
|
@@ -155,7 +226,27 @@ export interface GMDatagridRef {
|
|
|
155
226
|
field: string;
|
|
156
227
|
ignoreModifications?: boolean;
|
|
157
228
|
}) => void;
|
|
229
|
+
/** Programmatically enter row edit mode. */
|
|
230
|
+
startRowEditMode: (params: {
|
|
231
|
+
id: string | number;
|
|
232
|
+
}) => void;
|
|
233
|
+
/** Programmatically save or cancel and exit row edit mode. */
|
|
234
|
+
stopRowEditMode: (params: {
|
|
235
|
+
id: string | number;
|
|
236
|
+
ignoreModifications?: boolean;
|
|
237
|
+
}) => void;
|
|
238
|
+
/** Dynamically change edit mode ('cell' | 'row' | 'complete'). */
|
|
239
|
+
setEditMode: (mode: EditMode) => void;
|
|
240
|
+
/** Get all rows that have been edited / modified from their original baseline. */
|
|
241
|
+
getEditedRows: () => Row[];
|
|
242
|
+
/** Get original baseline rows before any edits. */
|
|
243
|
+
getOriginalRows: () => Row[];
|
|
244
|
+
/** Revert a single row to its original baseline values. */
|
|
245
|
+
revertRow: (id: string | number) => void;
|
|
246
|
+
/** Revert all edited rows to their original baseline values. */
|
|
247
|
+
revertAll: () => void;
|
|
158
248
|
}
|
|
249
|
+
export type EditMode = 'cell' | 'row' | 'complete';
|
|
159
250
|
export interface CellEditParams {
|
|
160
251
|
/** Row ID (from the `id` field). */
|
|
161
252
|
id: string | number;
|
|
@@ -166,6 +257,36 @@ export interface CellEditParams {
|
|
|
166
257
|
/** Full row object. */
|
|
167
258
|
row: Row;
|
|
168
259
|
}
|
|
260
|
+
export interface RowEditParams {
|
|
261
|
+
/** Row ID (from the `id` field). */
|
|
262
|
+
id: string | number;
|
|
263
|
+
/** Full row object. */
|
|
264
|
+
row: Row;
|
|
265
|
+
}
|
|
266
|
+
export interface AfterCellEditParams {
|
|
267
|
+
/** Row ID (from the `id` field). */
|
|
268
|
+
id: string | number;
|
|
269
|
+
/** Column field name that was edited. */
|
|
270
|
+
field: string;
|
|
271
|
+
/** Newly edited value. */
|
|
272
|
+
value: unknown;
|
|
273
|
+
/** Previous value of the cell before this edit. */
|
|
274
|
+
oldValue: unknown;
|
|
275
|
+
/** Full row object (including the updated cell value). */
|
|
276
|
+
row: Row;
|
|
277
|
+
/** Callback to update other fields in the row directly. */
|
|
278
|
+
updateRowValues: (updatedFields: Partial<Row>) => void;
|
|
279
|
+
}
|
|
280
|
+
export interface AggregationCalculatedParams {
|
|
281
|
+
/** Global footer aggregation results by column field. */
|
|
282
|
+
aggregations: AggregationResults;
|
|
283
|
+
/** Per-group aggregation results keyed by group key. */
|
|
284
|
+
groupSubtotals: Record<string, AggregationResults>;
|
|
285
|
+
/** Wasm engine calculated column subtotals. */
|
|
286
|
+
subtotals: Record<string, number>;
|
|
287
|
+
/** Current rows used in the calculation. */
|
|
288
|
+
rows: Row[];
|
|
289
|
+
}
|
|
169
290
|
export interface GMDatagridProps {
|
|
170
291
|
title: string;
|
|
171
292
|
columns: ColumnDef[];
|
|
@@ -185,6 +306,20 @@ export interface GMDatagridProps {
|
|
|
185
306
|
apiContext?: ApiContext;
|
|
186
307
|
/** MUI DataGrid-compatible save callback. Promise rejection reverts the cell. */
|
|
187
308
|
processRowUpdate?: (newRow: Row, oldRow: Row) => Row | Promise<Row>;
|
|
309
|
+
/**
|
|
310
|
+
* Edit mode for the grid:
|
|
311
|
+
* - `'cell'`: Single cell enters edit mode on double-click/Enter.
|
|
312
|
+
* - `'row'`: Entire row enters edit mode; all editable cells become inputs simultaneously.
|
|
313
|
+
* - `'complete'`: Full grid / spreadsheet mode; all editable cells in all rows are directly editable.
|
|
314
|
+
* @default 'cell'
|
|
315
|
+
*/
|
|
316
|
+
editMode?: EditMode;
|
|
317
|
+
/**
|
|
318
|
+
* When true, displays a MUI Badge component on edited cells showing that the value has changed
|
|
319
|
+
* and displaying the original value (e.g. on hover / title tooltip).
|
|
320
|
+
* @default false
|
|
321
|
+
*/
|
|
322
|
+
displayOldEditedValues?: boolean;
|
|
188
323
|
/**
|
|
189
324
|
* Called when a cell enters edit mode.
|
|
190
325
|
* MUI DataGrid compatible: receives `CellEditParams`.
|
|
@@ -195,6 +330,21 @@ export interface GMDatagridProps {
|
|
|
195
330
|
* MUI DataGrid compatible: receives `CellEditParams`.
|
|
196
331
|
*/
|
|
197
332
|
onCellEditStop?: (params: CellEditParams) => void;
|
|
333
|
+
/** Fired when a row enters edit mode (`editMode="row"`). */
|
|
334
|
+
onRowEditStart?: (params: RowEditParams) => void;
|
|
335
|
+
/** Fired when a row exits edit mode (`editMode="row"`). */
|
|
336
|
+
onRowEditStop?: (params: RowEditParams) => void;
|
|
337
|
+
/**
|
|
338
|
+
* Fired after a cell is edited/changed.
|
|
339
|
+
* Can return a partial row or call `params.updateRowValues` to update other columns in the same row
|
|
340
|
+
* (e.g. calculating price * quantity = subtotal, taxes, discounts).
|
|
341
|
+
*/
|
|
342
|
+
onAfterCellEdit?: (params: AfterCellEditParams) => Partial<Row> | Row | void | Promise<Partial<Row> | Row | void>;
|
|
343
|
+
/**
|
|
344
|
+
* Fired after aggregations and group subtotals have finished recalculating
|
|
345
|
+
* (e.g. after a row or cell edit updates values).
|
|
346
|
+
*/
|
|
347
|
+
onAggregationCalculated?: (params: AggregationCalculatedParams) => void;
|
|
198
348
|
/**
|
|
199
349
|
* Per-row/cell editability guard. Return `false` to prevent editing of a specific cell.
|
|
200
350
|
* Receives the same `CellEditParams` shape as MUI DataGrid's `isCellEditable`.
|
|
@@ -343,4 +493,15 @@ export interface GMDatagridProps {
|
|
|
343
493
|
model: AggregationModel;
|
|
344
494
|
};
|
|
345
495
|
};
|
|
496
|
+
/** Grid-level defaults for inline status toggles on STATUS columns. */
|
|
497
|
+
statusSwitch?: StatusSwitchConfig;
|
|
498
|
+
/** Custom toolbar slot components (bulk, creator, sync, actions). */
|
|
499
|
+
slot?: GridToolbarSlots;
|
|
500
|
+
/** Props merged into slot components. */
|
|
501
|
+
slotProps?: GridToolbarSlotProps;
|
|
502
|
+
/**
|
|
503
|
+
* When `slot.bulkAction` is set and `checkboxSelection` is false, enable checkboxes automatically.
|
|
504
|
+
* @default true
|
|
505
|
+
*/
|
|
506
|
+
autoCheckboxSelection?: boolean;
|
|
346
507
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Migration from legacy GMGridContainer (MUI X)
|
|
2
|
+
|
|
3
|
+
| Legacy (in-app) | npm `gm-datagrid` |
|
|
4
|
+
|-----------------|-------------------|
|
|
5
|
+
| `slot.bulkAction` + `GridMasiveActions` | `slot.bulkAction` + `GridBulkActionsHost` (automatic) |
|
|
6
|
+
| `slot.creator` + `GridRowCreatorButton` | `slot.creator` — host wraps dialog/permissions |
|
|
7
|
+
| `statusSwitch` on container | `statusSwitch` on `GMDatagrid` |
|
|
8
|
+
| Column `statusSwitch: true` | Same |
|
|
9
|
+
| `useGMGrid().handleRefresh` | Same |
|
|
10
|
+
| `ref.getSelectedRows()` (MUI apiRef) | `ref.getSelectedRows()` / `useGMGrid().getSelectedRows()` |
|
|
11
|
+
| `ref.apiRef`, `subscribeEvent` | **Not supported** (Wasm grid, no MUI DataGrid API) |
|
|
12
|
+
|
|
13
|
+
Import change:
|
|
14
|
+
|
|
15
|
+
```diff
|
|
16
|
+
- import { GMGridContainer, useGMGrid } from '../components/gm/grid/gm-grid-context';
|
|
17
|
+
+ import { GMDatagrid, GMGridContainer, useGMGrid } from 'gm-datagrid';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Ref rename: `handleRefresh` → `refresh()`, `setApiParameters` → `setParams()` on `GMGridContainerRef`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Inline status switch
|
|
2
|
+
|
|
3
|
+
Grid-level `statusSwitch` plus column `statusSwitch: true` enables an agnostic active/inactive `Switch` on `STATUS` columns (no custom `renderCell`).
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { GMDatagrid, ColumnDataTypesEnum } from 'gm-datagrid';
|
|
7
|
+
|
|
8
|
+
const STATUS_SWITCH = {
|
|
9
|
+
updateApi: async ({ id, status, row, context }) => {
|
|
10
|
+
const res = await fetch(`/api/items/${id}`, {
|
|
11
|
+
method: 'PATCH',
|
|
12
|
+
body: JSON.stringify({ status, companyId: context?.companyId }),
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) throw new Error('Update failed');
|
|
15
|
+
},
|
|
16
|
+
activeValue: 'A',
|
|
17
|
+
inactiveValue: 'I',
|
|
18
|
+
confirmBeforeUpdate: (row, next) => `Change "${row.name}" to ${next}?`,
|
|
19
|
+
successMessage: 'Status updated',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const columns = [
|
|
23
|
+
{
|
|
24
|
+
field: 'status',
|
|
25
|
+
headerName: 'Status',
|
|
26
|
+
type: ColumnDataTypesEnum.STATUS,
|
|
27
|
+
statusSwitch: true,
|
|
28
|
+
statusMap: { A: { label: 'Active', color: 'success' }, I: { label: 'Inactive', color: 'default' } },
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
<GMDatagrid columns={columns} statusSwitch={STATUS_SWITCH} sourceApi={list} title="Records" />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Per-column override: `statusSwitch: { updateApi: ... }` merges over grid defaults. `statusSwitch: false` disables the switch.
|
|
36
|
+
|
|
37
|
+
Exports: `RecordStatusSwitchCell`, `resolveColumnStatusSwitchConfig`.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Toolbar slots
|
|
2
|
+
|
|
3
|
+
`GMDatagrid` / `GMGridContainer` accept legacy-compatible `slot` and `slotProps`. The package does **not** implement dialogs, permissions, or app-specific APIs — only injects grid context into your components.
|
|
4
|
+
|
|
5
|
+
## Bulk actions
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { GMDatagrid, type GridBulkActionProps } from 'gm-datagrid';
|
|
9
|
+
|
|
10
|
+
function BulkMenu({ selectedRows, selectedCount, onRefresh, clearSelection }: GridBulkActionProps) {
|
|
11
|
+
if (selectedCount === 0) return null;
|
|
12
|
+
return (
|
|
13
|
+
<button type="button" onClick={() => { /* open drawer */ onRefresh(); }}>
|
|
14
|
+
Bulk ({selectedCount})
|
|
15
|
+
</button>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
<GMDatagrid
|
|
20
|
+
title="Items"
|
|
21
|
+
columns={columns}
|
|
22
|
+
sourceApi={fetchRows}
|
|
23
|
+
slot={{ bulkAction: BulkMenu }}
|
|
24
|
+
slotProps={{ bulkAction: { tooltip: 'Mass actions' } }}
|
|
25
|
+
/>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`autoCheckboxSelection` defaults to `true`: when `slot.bulkAction` is set, row checkboxes are enabled automatically.
|
|
29
|
+
|
|
30
|
+
## Creator
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
function CreateControl({ onRefresh, title }: { onRefresh: () => void; title?: string }) {
|
|
34
|
+
return <button type="button" onClick={() => openDialog(onRefresh)}>{title ?? 'Create'}</button>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
<GMDatagrid
|
|
38
|
+
slot={{ creator: CreateControl }}
|
|
39
|
+
slotProps={{ creator: { title: 'New record' } }}
|
|
40
|
+
/>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Synchronizer
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
<GMDatagrid
|
|
47
|
+
slotProps={{
|
|
48
|
+
synchronizer: {
|
|
49
|
+
handler: async () => { await syncFromRemote(); },
|
|
50
|
+
tooltip: 'Sync',
|
|
51
|
+
},
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`GridToolbarSynchronizer` calls `handler`, then grid `refresh()`.
|
|
57
|
+
|
|
58
|
+
## Custom toolbar actions
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
<GMDatagrid slot={{ actions: ExportCustomButton }} slotProps={{ actions: { foo: 1 } }} />
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## useGMGrid
|
|
65
|
+
|
|
66
|
+
Bulk components can use `useGMGrid()` inside the grid tree:
|
|
67
|
+
|
|
68
|
+
- `getSelectedRows()`, `selectedCount`, `handleRefresh`, `clearSelection`, `data`, `getRows()`
|
package/package.json
CHANGED
|
@@ -1,74 +1,76 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"name": "gm-datagrid",
|
|
3
|
+
"version": "0.1.24",
|
|
4
|
+
"description": "Enterprise Excel-like data grid with Rust/Wasm engine, featuring inline-aligned group subtotals and automatic group aggregate preloading",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"datagrid",
|
|
7
|
+
"data-grid",
|
|
8
|
+
"table",
|
|
9
|
+
"react",
|
|
10
|
+
"wasm",
|
|
11
|
+
"rust",
|
|
12
|
+
"excel",
|
|
13
|
+
"export",
|
|
14
|
+
"virtualization",
|
|
15
|
+
"enterprise"
|
|
16
|
+
],
|
|
17
|
+
"author": "GM Dev",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/gmdev/gm-datagrid"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/gmdev/gm-datagrid#readme",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/gm-datagrid.umd.cjs",
|
|
26
|
+
"module": "dist/gm-datagrid.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/gm-datagrid.js",
|
|
32
|
+
"require": "./dist/gm-datagrid.umd.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"docs"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "vite --host 0.0.0.0 --port 3100",
|
|
43
|
+
"build": "tsc -b && vite build",
|
|
44
|
+
"preview": "vite preview --host 0.0.0.0 --port 4173",
|
|
45
|
+
"prepublishOnly": "pnpm build",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest",
|
|
48
|
+
"lint": "eslint src --ext .ts,.tsx"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@mui/icons-material": ">=5",
|
|
52
|
+
"@mui/material": ">=5",
|
|
53
|
+
"react": ">=18",
|
|
54
|
+
"react-dom": ">=18"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"exceljs": "^4.4.0",
|
|
58
|
+
"match-sorter": "^8.3.0",
|
|
59
|
+
"moment": "^2.30.1",
|
|
60
|
+
"numeral": "^2.0.6"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@testing-library/react": "^16.0.0",
|
|
64
|
+
"@types/numeral": "^2.0.5",
|
|
65
|
+
"@types/react": "^19.0.0",
|
|
66
|
+
"@types/react-dom": "^19.0.0",
|
|
67
|
+
"@vitejs/plugin-react": "^4.3.0",
|
|
68
|
+
"jsdom": "^25.0.0",
|
|
69
|
+
"typescript": "^5.6.0",
|
|
70
|
+
"vite": "^6.0.0",
|
|
71
|
+
"vite-plugin-dts": "^4.5.4",
|
|
72
|
+
"vite-plugin-top-level-await": "^1.4.0",
|
|
73
|
+
"vite-plugin-wasm": "^3.3.0",
|
|
74
|
+
"vitest": "^2.1.0"
|
|
33
75
|
}
|
|
34
|
-
},
|
|
35
|
-
"files": [
|
|
36
|
-
"dist",
|
|
37
|
-
"README.md",
|
|
38
|
-
"LICENSE"
|
|
39
|
-
],
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"@mui/icons-material": ">=5",
|
|
42
|
-
"@mui/material": ">=5",
|
|
43
|
-
"react": ">=18",
|
|
44
|
-
"react-dom": ">=18"
|
|
45
|
-
},
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"exceljs": "^4.4.0",
|
|
48
|
-
"match-sorter": "^8.3.0",
|
|
49
|
-
"moment": "^2.30.1",
|
|
50
|
-
"numeral": "^2.0.6"
|
|
51
|
-
},
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@testing-library/react": "^16.0.0",
|
|
54
|
-
"@types/numeral": "^2.0.5",
|
|
55
|
-
"@types/react": "^19.0.0",
|
|
56
|
-
"@types/react-dom": "^19.0.0",
|
|
57
|
-
"@vitejs/plugin-react": "^4.3.0",
|
|
58
|
-
"jsdom": "^25.0.0",
|
|
59
|
-
"typescript": "^5.6.0",
|
|
60
|
-
"vite": "^6.0.0",
|
|
61
|
-
"vite-plugin-dts": "^4.5.4",
|
|
62
|
-
"vite-plugin-top-level-await": "^1.4.0",
|
|
63
|
-
"vite-plugin-wasm": "^3.3.0",
|
|
64
|
-
"vitest": "^2.1.0"
|
|
65
|
-
},
|
|
66
|
-
"scripts": {
|
|
67
|
-
"dev": "vite --host 0.0.0.0 --port 3100",
|
|
68
|
-
"build": "tsc -b && vite build",
|
|
69
|
-
"preview": "vite preview --host 0.0.0.0 --port 4173",
|
|
70
|
-
"test": "vitest run",
|
|
71
|
-
"test:watch": "vitest",
|
|
72
|
-
"lint": "eslint src --ext .ts,.tsx"
|
|
73
|
-
}
|
|
74
76
|
}
|