gm-datagrid 0.1.7 β†’ 0.1.10

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,8 +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
11
- - οΏ½πŸ“₯ One-click `.xlsx` export (generated in Wasm, no server round-trip)
10
+ - πŸ“… Date filter operators β€” is / is not / is after / is before / is empty / is not empty
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)
12
15
  - 🎨 Built on [MUI](https://mui.com/) β€” inherits your existing theme automatically
13
16
 
14
17
  ---
@@ -83,6 +86,7 @@ export default function ProductsPage() {
83
86
  | `onRowDetail` | `(row) => void` | β€” | Called when the user opens a row detail (double-click or menu action) |
84
87
  | `checkboxSelection` | `boolean` | `false` | Prepend a checkbox column for row selection |
85
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) |
86
90
 
87
91
  ### Pagination props
88
92
 
@@ -94,6 +98,40 @@ export default function ProductsPage() {
94
98
  | `pageSizeOptions` | `number[]` | `[25, 50, 100]` | Rows-per-page options shown in the footer selector |
95
99
  | `rowCount` | `number` | β€” | Total row count for server-side pagination |
96
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.
134
+
97
135
  ---
98
136
 
99
137
  ## Column definition (`ColumnDef`)
@@ -477,6 +515,9 @@ import type {
477
515
  RangeValue,
478
516
  SortKey,
479
517
  ApiContext,
518
+ GridLabels,
519
+ GridLocale,
520
+ FilterCellLabels,
480
521
  } from 'gm-datagrid'
481
522
 
482
523
  import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagrid'
@@ -484,6 +525,62 @@ import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagri
484
525
 
485
526
  ---
486
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} />
578
+ ```
579
+
580
+ All fields are optional β€” omit any key to fall back to the active `locale`.
581
+
582
+ ---
583
+
487
584
  ## Changelog
488
585
 
489
586
  See [CHANGELOG.md](https://github.com/gmdev/gm-datagrid/blob/main/CHANGELOG.md).
@@ -5,6 +5,23 @@ 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
26
  export type FilterCellValue = string | RangeValue | DateFilterValue | null;
10
27
  declare const NUMERIC_TYPES: ReadonlySet<string>;
@@ -18,26 +35,33 @@ declare function TextFilter({ value, onChange, placeholder, }: {
18
35
  onChange: (v: string) => void;
19
36
  placeholder?: string;
20
37
  }): import("react/jsx-runtime").JSX.Element;
21
- declare function NumericRangeFilter({ value, onChange, }: {
38
+ declare function NumericRangeFilter({ value, onChange, minLabel, maxLabel, }: {
22
39
  value: RangeValue;
23
40
  onChange: (v: RangeValue) => void;
41
+ minLabel?: string;
42
+ maxLabel?: string;
24
43
  }): import("react/jsx-runtime").JSX.Element;
25
- declare function EnumFilter({ value, onChange, options, }: {
44
+ declare function EnumFilter({ value, onChange, options, allLabel, }: {
26
45
  value: string;
27
46
  onChange: (v: string) => void;
28
47
  options: Array<{
29
48
  value: string;
30
49
  label: string;
31
50
  }>;
51
+ allLabel?: string;
32
52
  }): import("react/jsx-runtime").JSX.Element;
33
- declare function BooleanFilter({ value, onChange, }: {
53
+ declare function BooleanFilter({ value, onChange, allLabel, yesLabel, noLabel, }: {
34
54
  value: string;
35
55
  onChange: (v: string) => void;
56
+ allLabel?: string;
57
+ yesLabel?: string;
58
+ noLabel?: string;
36
59
  }): import("react/jsx-runtime").JSX.Element;
37
- declare function DateOperatorFilter({ value, onChange, withTime, }: {
60
+ declare function DateOperatorFilter({ value, onChange, withTime, dateOpLabels, }: {
38
61
  value: DateFilterValue;
39
62
  onChange: (v: DateFilterValue) => void;
40
63
  withTime?: boolean;
64
+ dateOpLabels?: Record<string, string>;
41
65
  }): import("react/jsx-runtime").JSX.Element;
42
66
  export interface FilterCellSlotProps {
43
67
  text?: Partial<React.ComponentProps<typeof TextFilter>>;
@@ -52,6 +76,8 @@ export interface FilterCellProps {
52
76
  onChange: (field: string, value: FilterCellValue) => void;
53
77
  /** Override sub-component props via slots */
54
78
  slotProps?: FilterCellSlotProps;
79
+ /** Translated labels for built-in strings */
80
+ labels?: FilterCellLabels;
55
81
  }
56
82
  export declare const FilterCell: React.NamedExoticComponent<FilterCellProps>;
57
83
  export default FilterCell;
@@ -2,11 +2,15 @@ import { GridEngine } from '../wasm/core_engine';
2
2
  interface UseExportProps {
3
3
  engineRef: React.RefObject<GridEngine | null>;
4
4
  title: string;
5
+ /** When provided, only columns whose field is in this set are included in the export. */
6
+ exportableFields?: Set<string>;
5
7
  }
6
8
  /**
7
9
  * Triggers a Wasm-side Excel export and downloads the result as a .xlsx file.
10
+ * If `exportableFields` is provided the Wasm engine is asked to restrict the
11
+ * export to those columns only; otherwise all columns are exported.
8
12
  */
9
- export declare function useExport({ engineRef, title }: UseExportProps): {
13
+ export declare function useExport({ engineRef, title, exportableFields }: UseExportProps): {
10
14
  handleExport: () => void;
11
15
  };
12
16
  export {};