gm-datagrid 0.1.6 β†’ 0.1.9

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,7 +7,11 @@ 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
+ - πŸ“… Date filter operators β€” is / is not / is after / is before / is empty / is not empty
10
11
  - πŸ“₯ One-click `.xlsx` export (generated in Wasm, no server round-trip)
12
+ - 🌐 Built-in **i18n** β€” `locale="es"` / `locale="en"` with full label overrides
13
+ - πŸ”’ **Feature flags** β€” selectively disable export, filters, sort, or grouping per instance
14
+ - 🧹 **Clear all filters** button in toolbar (desktop + mobile)
11
15
  - 🎨 Built on [MUI](https://mui.com/) β€” inherits your existing theme automatically
12
16
 
13
17
  ---
@@ -80,6 +84,53 @@ export default function ProductsPage() {
80
84
  | `quickFilterPlaceholder` | `string` | β€” | Placeholder text for the quick-filter input |
81
85
  | `rowColorGetter` | `(row) => { backgroundColor?, color? }` | β€” | Per-row color highlights (e.g. overdue rows in red) |
82
86
  | `onRowDetail` | `(row) => void` | β€” | Called when the user opens a row detail (double-click or menu action) |
87
+ | `checkboxSelection` | `boolean` | `false` | Prepend a checkbox column for row selection |
88
+ | `onRowSelectionChange` | `(rows: Row[]) => void` | β€” | Fires on every selection change with the full array of selected rows |
89
+ | `locale` | `'es' \| 'en'` | `'es'` | Built-in UI language. See [Internationalisation](#internationalisation-locale) |
90
+
91
+ ### Pagination props
92
+
93
+ | Prop | Type | Default | Description |
94
+ |---|---|---|---|
95
+ | `paginationMode` | `'client' \| 'server'` | `'client'` | Client-side (engine) or server-side pagination |
96
+ | `paginationModel` | `{ page: number; pageSize: number }` | `{ page: 0, pageSize: 25 }` | Controlled pagination state |
97
+ | `onPaginationModelChange` | `(model) => void` | β€” | Called when the user changes page or page size |
98
+ | `pageSizeOptions` | `number[]` | `[25, 50, 100]` | Rows-per-page options shown in the footer selector |
99
+ | `rowCount` | `number` | β€” | Total row count for server-side pagination |
100
+
101
+ ### Feature flags
102
+
103
+ Control which toolbar actions and column interactions are available without touching individual column definitions.
104
+
105
+ | Prop | Type | Default | Description |
106
+ |---|---|---|---|
107
+ | `exportable` | `boolean` | `true` | Show / hide the **Export** button in the toolbar |
108
+ | `exportableColumns` | `string[]` | β€” | Whitelist of `field` values included in the `.xlsx` export. Omit to export all visible columns |
109
+ | `filterable` | `boolean` | `true` | Show / hide the filter panel toggle button and the per-column filter row |
110
+ | `filterableColumns` | `string[]` | β€” | Only these fields render a filter input in the filter panel |
111
+ | `sortable` | `boolean` | `true` | Enable / disable sort on all column headers globally |
112
+ | `sortableColumns` | `string[]` | β€” | Only these fields respond to header click-to-sort. Overrides per-column `sortable` |
113
+ | `groupable` | `boolean` | `false` | Show / hide the group-by picker in the toolbar |
114
+ | `groupableColumns` | `string[]` | β€” | Fields offered in the group-by picker. Falls back to all columns when omitted |
115
+
116
+ **Example β€” read-only reporting grid with restricted export:**
117
+
118
+ ```tsx
119
+ <GMDatagrid
120
+ title="Sales Report"
121
+ columns={columns}
122
+ sourceApi={fetchSales}
123
+ sortable={false} // no sort at all
124
+ filterable // filters on (default)
125
+ filterableColumns={['customer', 'status', 'date']}
126
+ exportable
127
+ exportableColumns={['customer', 'total', 'date']} // exclude internal fields
128
+ groupable
129
+ groupableColumns={['customer', 'status']}
130
+ />
131
+ ```
132
+
133
+ > **Per-column flags still apply.** If you set `sortable={true}` globally but a column has `sortable: false` in its `ColumnDef`, that column remains non-sortable. The whitelist (`sortableColumns`) is intersected with the per-column flag β€” a field must pass both to be interactive.
83
134
 
84
135
  ---
85
136
 
@@ -118,8 +169,8 @@ interface ColumnDef {
118
169
  | `PERCENT` | Progress bar | 0–100 range |
119
170
  | `TAX` | Progress bar | 0–100 range |
120
171
  | `MARGIN` | Progress bar | 0–100 range |
121
- | `DATE` | `DD/MM/YYYY` | |
122
- | `DATE_TIME` | `DD/MM/YYYY HH:mm:ss` | |
172
+ | `DATE` | `DD/MM/YYYY` | Date operator filter panel |
173
+ | `DATE_TIME` | `DD/MM/YYYY HH:mm:ss` | Date operator filter panel |
123
174
  | `STATUS` | Coloured chip | Use `statusMap` to configure labels/colors |
124
175
  | `LABELS` | Array of chips | Cell value must be `string[]` |
125
176
  | `IMAGE` | 40 px avatar | Cell value is a URL |
@@ -168,6 +219,22 @@ export default function OrdersPage() {
168
219
  | `refresh()` | `() => void` | Re-fetches data with the current params |
169
220
  | `setParams(p)` | `(params: object) => void` | Replaces `apiParameters` and re-fetches |
170
221
 
222
+ `GMDatagrid` also supports a `ref` with an extended handle:
223
+
224
+ ```tsx
225
+ import { useRef } from 'react'
226
+ import { GMDatagrid } from 'gm-datagrid'
227
+ import type { GMDatagridRef } from 'gm-datagrid'
228
+
229
+ const ref = useRef<GMDatagridRef>(null)
230
+
231
+ // Programmatic row selection
232
+ ref.current?.getSelectedRows() // Row[]
233
+ ref.current?.clearSelection()
234
+ ref.current?.setSelectedIds(['id1', 'id2'])
235
+ ref.current?.refresh()
236
+ ```
237
+
171
238
  ---
172
239
 
173
240
  ## Context hook (`useGMGrid`)
@@ -191,6 +258,110 @@ function OrderSummary() {
191
258
  | `loading` | `boolean` | `true` while `sourceApi` is in flight |
192
259
  | `totalCount` | `number` | Total filtered row count (for pagination display) |
193
260
  | `handleRefresh` | `() => void` | Trigger a manual refresh |
261
+ | `selectedIds` | `Set<string>` | IDs of currently selected rows |
262
+
263
+ ---
264
+
265
+ ## Pagination
266
+
267
+ The grid renders a footer with page pills and a rows-per-page selector.
268
+
269
+ ### Client-side (default)
270
+
271
+ The Wasm engine slices rows in memory β€” no extra API calls on page change:
272
+
273
+ ```tsx
274
+ <GMDatagrid
275
+ title="Products"
276
+ columns={columns}
277
+ sourceApi={fetchProducts}
278
+ pageSizeOptions={[10, 25, 50]}
279
+ />
280
+ ```
281
+
282
+ ### Server-side
283
+
284
+ Control pagination yourself and pass the total row count:
285
+
286
+ ```tsx
287
+ const [paginationModel, setPaginationModel] = useState({ page: 0, pageSize: 25 })
288
+
289
+ async function fetchPage(params) {
290
+ const { page, pageSize } = params
291
+ const res = await api.get('/products', { page, pageSize })
292
+ return { success: true, data: res.rows, total: res.total }
293
+ }
294
+
295
+ <GMDatagrid
296
+ title="Products"
297
+ columns={columns}
298
+ sourceApi={fetchPage}
299
+ paginationMode="server"
300
+ paginationModel={paginationModel}
301
+ onPaginationModelChange={setPaginationModel}
302
+ rowCount={totalFromServer}
303
+ pageSizeOptions={[25, 50, 100]}
304
+ />
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Row selection
310
+
311
+ Enable checkboxes and respond to selection changes:
312
+
313
+ ```tsx
314
+ const [selected, setSelected] = useState([])
315
+
316
+ <GMDatagrid
317
+ title="Invoices"
318
+ columns={columns}
319
+ sourceApi={fetchInvoices}
320
+ checkboxSelection
321
+ onRowSelectionChange={setSelected}
322
+ />
323
+
324
+ // Bulk action button
325
+ <button disabled={selected.length === 0} onClick={() => bulkDelete(selected)}>
326
+ Delete {selected.length} rows
327
+ </button>
328
+ ```
329
+
330
+ Programmatic control via ref:
331
+
332
+ ```tsx
333
+ const ref = useRef<GMDatagridRef>(null)
334
+
335
+ ref.current?.getSelectedRows() // get current selection
336
+ ref.current?.setSelectedIds(['a', 'b']) // select programmatically
337
+ ref.current?.clearSelection() // deselect all
338
+ ```
339
+
340
+ ---
341
+
342
+ ## Date filter operators
343
+
344
+ `DATE` and `DATE_TIME` columns show an operator dropdown in the filter panel:
345
+
346
+ | Operator | Description |
347
+ |---|---|
348
+ | **is** | Exact date match |
349
+ | **is not** | Excludes the selected date |
350
+ | **is after** | Strictly after the selected date |
351
+ | **is on or after** | On or after the selected date |
352
+ | **is before** | Strictly before the selected date |
353
+ | **is on or before** | On or before the selected date |
354
+ | **is empty** | Cell is `null` or empty β€” no calendar shown |
355
+ | **is not empty** | Cell has any value β€” no calendar shown |
356
+
357
+ The filter value is represented as `DateFilterValue`:
358
+
359
+ ```ts
360
+ import type { DateFilterValue, DateFilterOp } from 'gm-datagrid'
361
+
362
+ // { op: 'gt', value: '2026-01-01' }
363
+ // { op: 'isNull', value: '' }
364
+ ```
194
365
 
195
366
  ---
196
367
 
@@ -333,17 +504,87 @@ All types are exported from the package root:
333
504
  import type {
334
505
  ColumnDef,
335
506
  GMDatagridProps,
507
+ GMDatagridRef,
336
508
  GMGridContainerRef,
337
509
  Row,
338
510
  CellRenderParams,
339
511
  FilterGroup,
512
+ FilterCellValue,
513
+ DateFilterValue,
514
+ DateFilterOp,
515
+ RangeValue,
340
516
  SortKey,
341
517
  ApiContext,
518
+ GridLabels,
519
+ GridLocale,
520
+ FilterCellLabels,
342
521
  } from 'gm-datagrid'
343
522
 
344
- import { ColumnDataTypesEnum } from 'gm-datagrid'
523
+ import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagrid'
524
+ ```
525
+
526
+ ---
527
+
528
+ ## Internationalisation (`locale`)
529
+
530
+ All built-in toolbar and filter labels are translated automatically when you set the `locale` prop.
531
+
532
+ ```tsx
533
+ // Spanish (default)
534
+ <GMDatagrid locale="es" title="Productos" columns={columns} sourceApi={fetchProducts} />
535
+
536
+ // English
537
+ <GMDatagrid locale="en" title="Products" columns={columns} sourceApi={fetchProducts} />
538
+ ```
539
+
540
+ ### Supported locales
541
+
542
+ | Code | Language |
543
+ |---|---|
544
+ | `'es'` | Spanish (default) |
545
+ | `'en'` | English |
546
+
547
+ ### Custom labels
548
+
549
+ Need a label that doesn't match either locale, or want to override a single string? Import `GridLabels` and pass a `labels` prop directly (takes priority over `locale`):
550
+
551
+ ```tsx
552
+ import type { GridLabels } from 'gm-datagrid'
553
+
554
+ const myLabels: GridLabels = {
555
+ search: 'Rechercher…',
556
+ filterBy: 'Filtrer par colonne',
557
+ hideFilters: 'Masquer les filtres',
558
+ clearFilters: 'Effacer les filtres',
559
+ all: 'Tous',
560
+ yes: 'Oui',
561
+ no: 'Non',
562
+ min: 'Min',
563
+ max: 'Max',
564
+ noGroup: 'Sans regroupement',
565
+ dateOps: {
566
+ equals: 'est',
567
+ not: 'n\'est pas',
568
+ gt: 'est après',
569
+ gte: 'est le ou après',
570
+ lt: 'est avant',
571
+ lte: 'est le ou avant',
572
+ isNull: 'est vide',
573
+ isNotNull: 'n\'est pas vide',
574
+ },
575
+ }
576
+
577
+ <GMDatagrid labels={myLabels} title="Produits" columns={columns} sourceApi={fetchProducts} />
345
578
  ```
346
579
 
580
+ All fields are optional β€” omit any key to fall back to the active `locale`.
581
+
582
+ ---
583
+
584
+ ## Changelog
585
+
586
+ See [CHANGELOG.md](https://github.com/gmdev/gm-datagrid/blob/main/CHANGELOG.md).
587
+
347
588
  ---
348
589
 
349
590
  ## License
@@ -1,49 +1,74 @@
1
1
  import { default as React } from 'react';
2
- import { ColumnDef } from '../types';
2
+ import { ColumnDef, DateFilterValue } from '../types';
3
3
  /** Range value used for numeric and date columns. */
4
4
  export interface RangeValue {
5
5
  min: string;
6
6
  max: string;
7
7
  }
8
+ /** Translatable labels for FilterCell sub-components. */
9
+ export interface FilterCellLabels {
10
+ /** Placeholder text for the text search input. */
11
+ search?: string;
12
+ /** "All" option label in enum / boolean filters. */
13
+ all?: string;
14
+ /** Boolean: true option. */
15
+ yes?: string;
16
+ /** Boolean: false option. */
17
+ no?: string;
18
+ /** Numeric range: lower bound tooltip. */
19
+ min?: string;
20
+ /** Numeric range: upper bound tooltip. */
21
+ max?: string;
22
+ /** Date operator dropdown labels keyed by DateFilterOp. */
23
+ dateOps?: Record<string, string>;
24
+ }
8
25
  /** All possible filter cell values */
9
- export type FilterCellValue = string | RangeValue | null;
26
+ export type FilterCellValue = string | RangeValue | DateFilterValue | null;
10
27
  declare const NUMERIC_TYPES: ReadonlySet<string>;
11
28
  declare const DATE_TYPES: ReadonlySet<string>;
12
29
  declare const ENUM_TYPES: ReadonlySet<string>;
13
30
  declare const NON_FILTERABLE: ReadonlySet<string>;
14
31
  export declare function isRangeValue(v: FilterCellValue): v is RangeValue;
32
+ export declare function isDateFilterValue(v: FilterCellValue): v is DateFilterValue;
15
33
  declare function TextFilter({ value, onChange, placeholder, }: {
16
34
  value: string;
17
35
  onChange: (v: string) => void;
18
36
  placeholder?: string;
19
37
  }): import("react/jsx-runtime").JSX.Element;
20
- declare function NumericRangeFilter({ value, onChange, }: {
38
+ declare function NumericRangeFilter({ value, onChange, minLabel, maxLabel, }: {
21
39
  value: RangeValue;
22
40
  onChange: (v: RangeValue) => void;
41
+ minLabel?: string;
42
+ maxLabel?: string;
23
43
  }): import("react/jsx-runtime").JSX.Element;
24
- declare function EnumFilter({ value, onChange, options, }: {
44
+ declare function EnumFilter({ value, onChange, options, allLabel, }: {
25
45
  value: string;
26
46
  onChange: (v: string) => void;
27
47
  options: Array<{
28
48
  value: string;
29
49
  label: string;
30
50
  }>;
51
+ allLabel?: string;
31
52
  }): import("react/jsx-runtime").JSX.Element;
32
- declare function BooleanFilter({ value, onChange, }: {
53
+ declare function BooleanFilter({ value, onChange, allLabel, yesLabel, noLabel, }: {
33
54
  value: string;
34
55
  onChange: (v: string) => void;
56
+ allLabel?: string;
57
+ yesLabel?: string;
58
+ noLabel?: string;
35
59
  }): import("react/jsx-runtime").JSX.Element;
36
- declare function DateFilter({ value, onChange, withTime, }: {
37
- value: string;
38
- onChange: (v: string) => void;
60
+ declare function DateOperatorFilter({ value, onChange, withTime, dateOpLabels, }: {
61
+ value: DateFilterValue;
62
+ onChange: (v: DateFilterValue) => void;
39
63
  withTime?: boolean;
64
+ dateOpLabels?: Record<string, string>;
40
65
  }): import("react/jsx-runtime").JSX.Element;
41
66
  export interface FilterCellSlotProps {
42
67
  text?: Partial<React.ComponentProps<typeof TextFilter>>;
43
68
  numeric?: Partial<React.ComponentProps<typeof NumericRangeFilter>>;
44
69
  enum?: Partial<React.ComponentProps<typeof EnumFilter>>;
45
70
  boolean?: Partial<React.ComponentProps<typeof BooleanFilter>>;
46
- date?: Partial<React.ComponentProps<typeof DateFilter>>;
71
+ date?: Partial<React.ComponentProps<typeof DateOperatorFilter>>;
47
72
  }
48
73
  export interface FilterCellProps {
49
74
  column: ColumnDef;
@@ -51,6 +76,8 @@ export interface FilterCellProps {
51
76
  onChange: (field: string, value: FilterCellValue) => void;
52
77
  /** Override sub-component props via slots */
53
78
  slotProps?: FilterCellSlotProps;
79
+ /** Translated labels for built-in strings */
80
+ labels?: FilterCellLabels;
54
81
  }
55
82
  export declare const FilterCell: React.NamedExoticComponent<FilterCellProps>;
56
83
  export default FilterCell;