gm-datagrid 0.1.5 → 0.1.7

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,8 @@ 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
- - 📥 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)
11
12
  - 🎨 Built on [MUI](https://mui.com/) — inherits your existing theme automatically
12
13
 
13
14
  ---
@@ -80,6 +81,18 @@ export default function ProductsPage() {
80
81
  | `quickFilterPlaceholder` | `string` | — | Placeholder text for the quick-filter input |
81
82
  | `rowColorGetter` | `(row) => { backgroundColor?, color? }` | — | Per-row color highlights (e.g. overdue rows in red) |
82
83
  | `onRowDetail` | `(row) => void` | — | Called when the user opens a row detail (double-click or menu action) |
84
+ | `checkboxSelection` | `boolean` | `false` | Prepend a checkbox column for row selection |
85
+ | `onRowSelectionChange` | `(rows: Row[]) => void` | — | Fires on every selection change with the full array of selected rows |
86
+
87
+ ### Pagination props
88
+
89
+ | Prop | Type | Default | Description |
90
+ |---|---|---|---|
91
+ | `paginationMode` | `'client' \| 'server'` | `'client'` | Client-side (engine) or server-side pagination |
92
+ | `paginationModel` | `{ page: number; pageSize: number }` | `{ page: 0, pageSize: 25 }` | Controlled pagination state |
93
+ | `onPaginationModelChange` | `(model) => void` | — | Called when the user changes page or page size |
94
+ | `pageSizeOptions` | `number[]` | `[25, 50, 100]` | Rows-per-page options shown in the footer selector |
95
+ | `rowCount` | `number` | — | Total row count for server-side pagination |
83
96
 
84
97
  ---
85
98
 
@@ -118,8 +131,8 @@ interface ColumnDef {
118
131
  | `PERCENT` | Progress bar | 0–100 range |
119
132
  | `TAX` | Progress bar | 0–100 range |
120
133
  | `MARGIN` | Progress bar | 0–100 range |
121
- | `DATE` | `DD/MM/YYYY` | |
122
- | `DATE_TIME` | `DD/MM/YYYY HH:mm:ss` | |
134
+ | `DATE` | `DD/MM/YYYY` | Date operator filter panel |
135
+ | `DATE_TIME` | `DD/MM/YYYY HH:mm:ss` | Date operator filter panel |
123
136
  | `STATUS` | Coloured chip | Use `statusMap` to configure labels/colors |
124
137
  | `LABELS` | Array of chips | Cell value must be `string[]` |
125
138
  | `IMAGE` | 40 px avatar | Cell value is a URL |
@@ -168,6 +181,22 @@ export default function OrdersPage() {
168
181
  | `refresh()` | `() => void` | Re-fetches data with the current params |
169
182
  | `setParams(p)` | `(params: object) => void` | Replaces `apiParameters` and re-fetches |
170
183
 
184
+ `GMDatagrid` also supports a `ref` with an extended handle:
185
+
186
+ ```tsx
187
+ import { useRef } from 'react'
188
+ import { GMDatagrid } from 'gm-datagrid'
189
+ import type { GMDatagridRef } from 'gm-datagrid'
190
+
191
+ const ref = useRef<GMDatagridRef>(null)
192
+
193
+ // Programmatic row selection
194
+ ref.current?.getSelectedRows() // Row[]
195
+ ref.current?.clearSelection()
196
+ ref.current?.setSelectedIds(['id1', 'id2'])
197
+ ref.current?.refresh()
198
+ ```
199
+
171
200
  ---
172
201
 
173
202
  ## Context hook (`useGMGrid`)
@@ -191,6 +220,110 @@ function OrderSummary() {
191
220
  | `loading` | `boolean` | `true` while `sourceApi` is in flight |
192
221
  | `totalCount` | `number` | Total filtered row count (for pagination display) |
193
222
  | `handleRefresh` | `() => void` | Trigger a manual refresh |
223
+ | `selectedIds` | `Set<string>` | IDs of currently selected rows |
224
+
225
+ ---
226
+
227
+ ## Pagination
228
+
229
+ The grid renders a footer with page pills and a rows-per-page selector.
230
+
231
+ ### Client-side (default)
232
+
233
+ The Wasm engine slices rows in memory — no extra API calls on page change:
234
+
235
+ ```tsx
236
+ <GMDatagrid
237
+ title="Products"
238
+ columns={columns}
239
+ sourceApi={fetchProducts}
240
+ pageSizeOptions={[10, 25, 50]}
241
+ />
242
+ ```
243
+
244
+ ### Server-side
245
+
246
+ Control pagination yourself and pass the total row count:
247
+
248
+ ```tsx
249
+ const [paginationModel, setPaginationModel] = useState({ page: 0, pageSize: 25 })
250
+
251
+ async function fetchPage(params) {
252
+ const { page, pageSize } = params
253
+ const res = await api.get('/products', { page, pageSize })
254
+ return { success: true, data: res.rows, total: res.total }
255
+ }
256
+
257
+ <GMDatagrid
258
+ title="Products"
259
+ columns={columns}
260
+ sourceApi={fetchPage}
261
+ paginationMode="server"
262
+ paginationModel={paginationModel}
263
+ onPaginationModelChange={setPaginationModel}
264
+ rowCount={totalFromServer}
265
+ pageSizeOptions={[25, 50, 100]}
266
+ />
267
+ ```
268
+
269
+ ---
270
+
271
+ ## Row selection
272
+
273
+ Enable checkboxes and respond to selection changes:
274
+
275
+ ```tsx
276
+ const [selected, setSelected] = useState([])
277
+
278
+ <GMDatagrid
279
+ title="Invoices"
280
+ columns={columns}
281
+ sourceApi={fetchInvoices}
282
+ checkboxSelection
283
+ onRowSelectionChange={setSelected}
284
+ />
285
+
286
+ // Bulk action button
287
+ <button disabled={selected.length === 0} onClick={() => bulkDelete(selected)}>
288
+ Delete {selected.length} rows
289
+ </button>
290
+ ```
291
+
292
+ Programmatic control via ref:
293
+
294
+ ```tsx
295
+ const ref = useRef<GMDatagridRef>(null)
296
+
297
+ ref.current?.getSelectedRows() // get current selection
298
+ ref.current?.setSelectedIds(['a', 'b']) // select programmatically
299
+ ref.current?.clearSelection() // deselect all
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Date filter operators
305
+
306
+ `DATE` and `DATE_TIME` columns show an operator dropdown in the filter panel:
307
+
308
+ | Operator | Description |
309
+ |---|---|
310
+ | **is** | Exact date match |
311
+ | **is not** | Excludes the selected date |
312
+ | **is after** | Strictly after the selected date |
313
+ | **is on or after** | On or after the selected date |
314
+ | **is before** | Strictly before the selected date |
315
+ | **is on or before** | On or before the selected date |
316
+ | **is empty** | Cell is `null` or empty — no calendar shown |
317
+ | **is not empty** | Cell has any value — no calendar shown |
318
+
319
+ The filter value is represented as `DateFilterValue`:
320
+
321
+ ```ts
322
+ import type { DateFilterValue, DateFilterOp } from 'gm-datagrid'
323
+
324
+ // { op: 'gt', value: '2026-01-01' }
325
+ // { op: 'isNull', value: '' }
326
+ ```
194
327
 
195
328
  ---
196
329
 
@@ -333,19 +466,30 @@ All types are exported from the package root:
333
466
  import type {
334
467
  ColumnDef,
335
468
  GMDatagridProps,
469
+ GMDatagridRef,
336
470
  GMGridContainerRef,
337
471
  Row,
338
472
  CellRenderParams,
339
473
  FilterGroup,
474
+ FilterCellValue,
475
+ DateFilterValue,
476
+ DateFilterOp,
477
+ RangeValue,
340
478
  SortKey,
341
479
  ApiContext,
342
480
  } from 'gm-datagrid'
343
481
 
344
- import { ColumnDataTypesEnum } from 'gm-datagrid'
482
+ import { ColumnDataTypesEnum, isRangeValue, isDateFilterValue } from 'gm-datagrid'
345
483
  ```
346
484
 
347
485
  ---
348
486
 
487
+ ## Changelog
488
+
489
+ See [CHANGELOG.md](https://github.com/gmdev/gm-datagrid/blob/main/CHANGELOG.md).
490
+
491
+ ---
492
+
349
493
  ## License
350
494
 
351
495
  MIT
@@ -1,10 +1,12 @@
1
- import { GMDatagridProps } from './types';
1
+ import { GMDatagridProps, GMDatagridRef } from './types';
2
2
  /**
3
3
  * GMDatagrid — Rust/Wasm-powered enterprise grid with Excel-like editing.
4
4
  * Drop-in replacement for GMGridContainer.
5
5
  *
6
6
  * Usage:
7
- * <GMDatagrid title="Productos" sourceApi={productsApi.list} columns={columns} />
7
+ * const ref = useRef<GMDatagridRef>(null);
8
+ * <GMDatagrid ref={ref} title="Productos" sourceApi={productsApi.list} columns={columns}
9
+ * checkboxSelection onRowSelectionChange={(rows) => console.log(rows)} />
8
10
  */
9
- export declare function GMDatagrid(props: GMDatagridProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare const GMDatagrid: import('react').ForwardRefExoticComponent<GMDatagridProps & import('react').RefAttributes<GMDatagridRef>>;
10
12
  export default GMDatagrid;
@@ -1,4 +1,6 @@
1
- import { GMDatagridProps } from './types';
2
- export default function GMDatagridInner({ outerProps }: {
1
+ import { default as React } from 'react';
2
+ import { GMDatagridProps, GMDatagridRef } from './types';
3
+ export default function GMDatagridInner({ outerProps, innerRef, }: {
3
4
  outerProps: GMDatagridProps;
5
+ innerRef?: React.RefObject<GMDatagridRef | null>;
4
6
  }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { default as React } from 'react';
2
+ import { ColumnDef, DateFilterValue } from '../types';
3
+ /** Range value used for numeric and date columns. */
4
+ export interface RangeValue {
5
+ min: string;
6
+ max: string;
7
+ }
8
+ /** All possible filter cell values */
9
+ export type FilterCellValue = string | RangeValue | DateFilterValue | null;
10
+ declare const NUMERIC_TYPES: ReadonlySet<string>;
11
+ declare const DATE_TYPES: ReadonlySet<string>;
12
+ declare const ENUM_TYPES: ReadonlySet<string>;
13
+ declare const NON_FILTERABLE: ReadonlySet<string>;
14
+ export declare function isRangeValue(v: FilterCellValue): v is RangeValue;
15
+ export declare function isDateFilterValue(v: FilterCellValue): v is DateFilterValue;
16
+ declare function TextFilter({ value, onChange, placeholder, }: {
17
+ value: string;
18
+ onChange: (v: string) => void;
19
+ placeholder?: string;
20
+ }): import("react/jsx-runtime").JSX.Element;
21
+ declare function NumericRangeFilter({ value, onChange, }: {
22
+ value: RangeValue;
23
+ onChange: (v: RangeValue) => void;
24
+ }): import("react/jsx-runtime").JSX.Element;
25
+ declare function EnumFilter({ value, onChange, options, }: {
26
+ value: string;
27
+ onChange: (v: string) => void;
28
+ options: Array<{
29
+ value: string;
30
+ label: string;
31
+ }>;
32
+ }): import("react/jsx-runtime").JSX.Element;
33
+ declare function BooleanFilter({ value, onChange, }: {
34
+ value: string;
35
+ onChange: (v: string) => void;
36
+ }): import("react/jsx-runtime").JSX.Element;
37
+ declare function DateOperatorFilter({ value, onChange, withTime, }: {
38
+ value: DateFilterValue;
39
+ onChange: (v: DateFilterValue) => void;
40
+ withTime?: boolean;
41
+ }): import("react/jsx-runtime").JSX.Element;
42
+ export interface FilterCellSlotProps {
43
+ text?: Partial<React.ComponentProps<typeof TextFilter>>;
44
+ numeric?: Partial<React.ComponentProps<typeof NumericRangeFilter>>;
45
+ enum?: Partial<React.ComponentProps<typeof EnumFilter>>;
46
+ boolean?: Partial<React.ComponentProps<typeof BooleanFilter>>;
47
+ date?: Partial<React.ComponentProps<typeof DateOperatorFilter>>;
48
+ }
49
+ export interface FilterCellProps {
50
+ column: ColumnDef;
51
+ value: FilterCellValue;
52
+ onChange: (field: string, value: FilterCellValue) => void;
53
+ /** Override sub-component props via slots */
54
+ slotProps?: FilterCellSlotProps;
55
+ }
56
+ export declare const FilterCell: React.NamedExoticComponent<FilterCellProps>;
57
+ export default FilterCell;
58
+ export { NUMERIC_TYPES, DATE_TYPES, ENUM_TYPES, NON_FILTERABLE };
@@ -18,12 +18,22 @@ interface GridContextValue extends DataSetState {
18
18
  expandedGroups: Set<string>;
19
19
  groupRows: Record<string, Row[]>;
20
20
  toggleGroup: (key: string) => void;
21
+ selectedIds: Set<string>;
22
+ toggleRowSelection: (id: string) => void;
23
+ toggleSelectAll: () => void;
24
+ clearSelection: () => void;
25
+ setSelectedIds: (ids: string[]) => void;
26
+ isAllSelected: boolean;
27
+ isSomeSelected: boolean;
28
+ textSearch: string;
29
+ setTextSearch: (v: string) => void;
21
30
  }
22
31
  interface GridProviderProps {
23
32
  dataset: DataSetState;
24
33
  children: React.ReactNode;
25
34
  defaultPageSize?: number;
35
+ onRowSelectionChange?: (rows: Row[]) => void;
26
36
  }
27
- export declare function GridProvider({ dataset, children, defaultPageSize }: GridProviderProps): import("react/jsx-runtime").JSX.Element;
37
+ export declare function GridProvider({ dataset, children, defaultPageSize, onRowSelectionChange }: GridProviderProps): import("react/jsx-runtime").JSX.Element;
28
38
  export declare function useGMGrid(): GridContextValue;
29
39
  export {};