gm-datagrid 0.1.12 โ†’ 0.1.14

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
@@ -9,6 +9,7 @@ Enterprise-grade, Excel-like data grid for React โ€” powered by a **Rust/WebAsse
9
9
  - ๐Ÿ“Š Column subtotals updated live as filters change
10
10
  - ๐Ÿ“… Date filter operators โ€” is / is not / is after / is before / is empty / is not empty
11
11
  - ๐Ÿ“ฅ One-click `.xlsx` export (generated in Wasm, no server round-trip)
12
+ - ๐Ÿ“ค **Multi-format export** โ€” toolbar picker for `xlsx`, `csv`, `txt`, `json`
12
13
  - ๐ŸŒ Built-in **i18n** โ€” `locale="es"` / `locale="en"` with full label overrides
13
14
  - ๐Ÿ”’ **Feature flags** โ€” selectively disable export, filters, sort, or grouping per instance
14
15
  - ๐Ÿงน **Clear all filters** button in toolbar (desktop + mobile)
@@ -105,6 +106,7 @@ Control which toolbar actions and column interactions are available without touc
105
106
  | Prop | Type | Default | Description |
106
107
  |---|---|---|---|
107
108
  | `exportable` | `boolean` | `true` | Show / hide the **Export** button in the toolbar |
109
+ | `exportFormats` | `ExportFormat[]` | `['xlsx', 'csv']` | Which formats appear in the export menu. A single format skips the menu and downloads directly |
108
110
  | `exportableColumns` | `string[]` | โ€” | Whitelist of `field` values included in the `.xlsx` export. Omit to export all visible columns |
109
111
  | `filterable` | `boolean` | `true` | Show / hide the filter panel toggle button and the per-column filter row |
110
112
  | `filterableColumns` | `string[]` | โ€” | Only these fields render a filter input in the filter panel |
@@ -478,7 +480,39 @@ function App() {
478
480
 
479
481
  The toolbar includes an **Export** button that generates a `.xlsx` file entirely inside the Wasm engine โ€” no server call required. The exported file reflects the current sort and filter state.
480
482
 
481
- Column formatting is preserved in the export:
483
+ ---
484
+
485
+ ## Multi-format export
486
+
487
+ By default the toolbar shows an export button that downloads both `.xlsx` and `.csv`. When more than one format is enabled a **format picker menu** opens on click:
488
+
489
+ ```tsx
490
+ <GMDatagrid
491
+ title="Products"
492
+ columns={columns}
493
+ sourceApi={fetchProducts}
494
+ exportFormats={['xlsx', 'csv', 'txt', 'json']} // all four formats
495
+ />
496
+
497
+ // xlsx only โ€” no menu, direct download
498
+ <GMDatagrid exportFormats={['xlsx']} ... />
499
+
500
+ // Disable export entirely
501
+ <GMDatagrid exportable={false} ... />
502
+ ```
503
+
504
+ ### Supported formats
505
+
506
+ | Format | Extension | Notes |
507
+ |---|---|---|
508
+ | `xlsx` | `.xlsx` | Generated by Rust/Wasm; preserves number & date formats, column widths |
509
+ | `csv` | `.csv` | RFC 4180, UTF-8 BOM โ€” opens correctly in Excel |
510
+ | `txt` | `.txt` | Tab-separated values โ€” paste directly into Excel |
511
+ | `json` | `.json` | Array of objects keyed by column `field` |
512
+
513
+ `ACTION`, `MENU_ACTION`, and `IMAGE` columns are automatically excluded from CSV/TXT/JSON exports.
514
+
515
+ Column formatting is preserved in the xlsx export:
482
516
 
483
517
  - `PRICE` / `TOTAL` columns use Excel number formats
484
518
  - `DATE` / `DATE_TIME` columns use Excel date formats
@@ -508,6 +542,8 @@ import type {
508
542
  GMGridContainerRef,
509
543
  Row,
510
544
  CellRenderParams,
545
+ CellEditParams,
546
+ ExportFormat,
511
547
  FilterGroup,
512
548
  FilterCellValue,
513
549
  DateFilterValue,
@@ -525,6 +561,88 @@ import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagri
525
561
 
526
562
  ---
527
563
 
564
+ ## Editing
565
+
566
+ ### Feature flags
567
+
568
+ | Prop | Type | Default | Description |
569
+ |---|---|---|---|
570
+ | `editable` | `boolean` | `false` | Enable / disable inline editing globally |
571
+ | `editableColumns` | `string[]` | โ€” | Only these fields are editable (overrides per-column `editable` flag) |
572
+
573
+ ### Per-column editability
574
+
575
+ Set `editable: true` on each `ColumnDef` you want users to edit. The global `editable` prop and `editableColumns` whitelist take precedence.
576
+
577
+ ### Editing events (MUI DataGrid compatible)
578
+
579
+ ```tsx
580
+ import type { CellEditParams } from 'gm-datagrid'
581
+
582
+ <GMDatagrid
583
+ title="Products"
584
+ columns={columns}
585
+ sourceApi={fetchProducts}
586
+ editable
587
+ editableColumns={['name', 'price', 'stock']}
588
+ processRowUpdate={async (newRow, oldRow) => {
589
+ await api.patch(`/products/${newRow.id}`, newRow)
590
+ return newRow
591
+ }}
592
+ onCellEditStart={(params: CellEditParams) => {
593
+ console.log('editing started', params.field, params.value)
594
+ }}
595
+ onCellEditStop={(params: CellEditParams) => {
596
+ console.log('editing stopped', params.field)
597
+ }}
598
+ isCellEditable={(params: CellEditParams) => {
599
+ // Only allow editing rows that are in DRAFT status
600
+ return params.row.status === 'DRAFT'
601
+ }}
602
+ />
603
+ ```
604
+
605
+ ### Programmatic editing via `ref`
606
+
607
+ ```tsx
608
+ import { useRef } from 'react'
609
+ import { GMDatagrid } from 'gm-datagrid'
610
+ import type { GMDatagridRef } from 'gm-datagrid'
611
+
612
+ const ref = useRef<GMDatagridRef>(null)
613
+
614
+ // Start editing a specific cell
615
+ ref.current?.startCellEditMode({ id: 'row-1', field: 'name' })
616
+
617
+ // Save and exit
618
+ ref.current?.stopCellEditMode({ id: 'row-1', field: 'name' })
619
+
620
+ // Discard changes and exit
621
+ ref.current?.stopCellEditMode({ id: 'row-1', field: 'name', ignoreModifications: true })
622
+ ```
623
+
624
+ ### `CellEditParams` interface
625
+
626
+ ```ts
627
+ interface CellEditParams {
628
+ id: string | number // row id
629
+ field: string // column field name
630
+ value: unknown // current cell value
631
+ row: Row // full row object
632
+ }
633
+ ```
634
+
635
+ ### Editability hierarchy
636
+
637
+ All four levels must pass for a cell to be editable:
638
+
639
+ 1. `editable` prop โ€” global feature flag (`false` by default)
640
+ 2. `editableColumns` whitelist โ€” if set, field must be in the list
641
+ 3. `col.editable` โ€” per-column flag in `ColumnDef`
642
+ 4. `isCellEditable(params)` callback โ€” per-row guard
643
+
644
+ ---
645
+
528
646
  ## Internationalisation (`locale`)
529
647
 
530
648
  All built-in toolbar and filter labels are translated automatically when you set the `locale` prop.
@@ -1,16 +1,18 @@
1
+ import { default as React } from 'react';
1
2
  import { GridEngine } from '../wasm/core_engine';
3
+ import { ColumnDef, ExportFormat } from '../types';
2
4
  interface UseExportProps {
3
5
  engineRef: React.RefObject<GridEngine | null>;
4
6
  title: string;
5
7
  /** When provided, only columns whose field is in this set are included in the export. */
6
8
  exportableFields?: Set<string>;
9
+ /** All visible columns โ€” used to build CSV/TXT/JSON exports. */
10
+ columns: ColumnDef[];
11
+ /** Formats enabled for this grid instance (default: ['xlsx', 'csv']). */
12
+ exportFormats?: ExportFormat[];
7
13
  }
8
- /**
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.
12
- */
13
- export declare function useExport({ engineRef, title, exportableFields }: UseExportProps): {
14
- handleExport: () => void;
14
+ export declare function useExport({ engineRef, title, exportableFields, columns, exportFormats, }: UseExportProps): {
15
+ handleExport: (format: ExportFormat) => void;
16
+ exportFormats: ExportFormat[];
15
17
  };
16
18
  export {};
@@ -1,4 +1,4 @@
1
- import { CellCoord, ColumnDef, Row } from '../types';
1
+ import { CellCoord, CellEditParams, ColumnDef, Row } from '../types';
2
2
  interface UseInlineEditProps {
3
3
  visibleRows: Row[];
4
4
  columns: ColumnDef[];
@@ -6,6 +6,16 @@ interface UseInlineEditProps {
6
6
  engineReady: boolean;
7
7
  processRowUpdate?: (newRow: Row, oldRow: Row) => Row | Promise<Row>;
8
8
  onCellError: (rowId: string, message: string) => void;
9
+ /** Fired when a cell enters edit mode (MUI DataGrid compatible). */
10
+ onCellEditStart?: (params: CellEditParams) => void;
11
+ /** Fired when a cell exits edit mode (MUI DataGrid compatible). */
12
+ onCellEditStop?: (params: CellEditParams) => void;
13
+ /** Per-cell editability guard โ€” return false to block editing. */
14
+ isCellEditable?: (params: CellEditParams) => boolean;
15
+ /** Global editable flag โ€” when false, no cell can be edited. */
16
+ editableFlag?: boolean;
17
+ /** Whitelist of editable fields โ€” overrides per-column editable flag when set. */
18
+ editableSet?: Set<string> | null;
9
19
  }
10
20
  interface InlineEditState {
11
21
  editingCell: CellCoord | null;
@@ -17,8 +27,19 @@ interface InlineEditState {
17
27
  }
18
28
  /**
19
29
  * Manages Excel-like inline cell editing.
30
+ *
31
+ * Fires MUI DataGrid-compatible events:
32
+ * onCellEditStart({ id, field, value, row }) โ€” when a cell enters edit mode
33
+ * onCellEditStop({ id, field, value, row }) โ€” when a cell exits edit mode
34
+ *
35
+ * Editability hierarchy (all must pass):
36
+ * 1. editableFlag (global feature flag, default false)
37
+ * 2. editableSet (column whitelist from editableColumns prop)
38
+ * 3. col.editable (per-column ColumnDef flag)
39
+ * 4. isCellEditable(params) (per-row/cell callback)
40
+ *
20
41
  * On save: calls processRowUpdate (async), reverts on rejection.
21
42
  * On escape: discards changes.
22
43
  */
23
- export declare function useInlineEdit({ visibleRows, columns, engine, engineReady, processRowUpdate, onCellError, }: UseInlineEditProps): InlineEditState;
44
+ export declare function useInlineEdit({ visibleRows, columns, engine, engineReady, processRowUpdate, onCellError, onCellEditStart, onCellEditStop, isCellEditable, editableFlag, editableSet, }: UseInlineEditProps): InlineEditState;
24
45
  export {};