@jielga/tmdatagrid 2.0.0-beta.9 → 2.0.1
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 +5 -212
- package/dist/index.d.ts +1281 -768
- package/dist/index.js +4607 -3250
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/docs/adding-rows.md +132 -0
- package/docs/anatomy.md +119 -0
- package/docs/card-view.md +108 -0
- package/docs/cell-selection.md +194 -0
- package/docs/column-layout.md +182 -0
- package/docs/column-menu.md +66 -0
- package/docs/columns.md +269 -0
- package/docs/components.md +311 -0
- package/docs/draft-store.md +242 -0
- package/docs/editing.md +303 -0
- package/docs/editors.md +250 -0
- package/docs/export.md +319 -0
- package/docs/filtering.md +362 -0
- package/docs/getting-started.md +123 -0
- package/docs/grouping.md +165 -0
- package/docs/loading-and-empty.md +92 -0
- package/docs/localization.md +79 -0
- package/docs/menu.md +143 -0
- package/docs/migrating-to-2.md +163 -0
- package/docs/pagination.md +144 -0
- package/docs/persistence.md +114 -0
- package/docs/portfolio-rebalancer.md +94 -0
- package/docs/query-builder.md +179 -0
- package/docs/quick-search.md +84 -0
- package/docs/row-details.md +115 -0
- package/docs/row-interaction.md +149 -0
- package/docs/row-pinning.md +132 -0
- package/docs/row-selection.md +136 -0
- package/docs/row-styling.md +133 -0
- package/docs/scrolling.md +112 -0
- package/docs/server-query.md +246 -0
- package/docs/server-side.md +206 -0
- package/docs/sorting.md +101 -0
- package/docs/styling.md +126 -0
- package/docs/summary-row.md +76 -0
- package/docs/testing.md +744 -0
- package/docs/toolbar.md +161 -0
- package/docs/use-tm-data-grid.md +361 -0
- package/package.json +22 -46
- package/skills/appearance/SKILL.md +72 -19
- package/skills/cell-selection/SKILL.md +49 -48
- package/skills/columns/SKILL.md +125 -70
- package/skills/columns/references/columns-api.md +59 -0
- package/skills/data/SKILL.md +112 -18
- package/skills/editing/SKILL.md +76 -42
- package/skills/editing/references/common-mistakes.md +77 -69
- package/skills/editing/references/editing-api.md +25 -20
- package/skills/editing/references/editors-and-validation.md +80 -18
- package/skills/filtering/SKILL.md +155 -41
- package/skills/getting-started/SKILL.md +116 -16
- package/skills/grouping/SKILL.md +31 -16
- package/skills/migrating-to-2/SKILL.md +244 -0
- package/skills/options/SKILL.md +24 -12
- package/skills/rows/SKILL.md +22 -18
- package/skills/rows/references/rows-api.md +10 -6
- package/skills/server-side/SKILL.md +170 -17
- package/skills/testing/SKILL.md +150 -32
- package/skills/testing-components/SKILL.md +230 -0
- package/skills/testing-editing/SKILL.md +240 -0
- package/src/{tmdatagrid/components → components}/TMDataGrid.tsx +38 -21
- package/src/{tmdatagrid/components → components}/TMDataGridCellEditor.tsx +54 -8
- package/src/{tmdatagrid/components → components}/TMDataGridColumnsPanel.module.css +5 -1
- package/src/{tmdatagrid/components → components}/TMDataGridColumnsPanel.tsx +47 -55
- package/src/{tmdatagrid/components → components}/TMDataGridDetailsColumn.tsx +5 -51
- package/src/{tmdatagrid/components → components}/TMDataGridDraftActions.tsx +41 -24
- package/src/{tmdatagrid/components → components}/TMDataGridEditColumn.tsx +12 -59
- package/src/{tmdatagrid/components → components}/TMDataGridEntryRows.tsx +164 -92
- package/src/components/TMDataGridExportPicker.module.css +77 -0
- package/src/components/TMDataGridExportPicker.tsx +234 -0
- package/src/components/TMDataGridFilterPanel.module.css +54 -0
- package/src/components/TMDataGridFilterPanel.tsx +348 -0
- package/src/{tmdatagrid/components → components}/TMDataGridFilterPills.tsx +15 -8
- package/src/components/TMDataGridFilterSurface.module.css +54 -0
- package/src/components/TMDataGridFilterSurface.tsx +167 -0
- package/src/{tmdatagrid/components → components}/TMDataGridFooter.tsx +53 -90
- package/src/{tmdatagrid/components → components}/TMDataGridGroupColumn.tsx +5 -69
- package/src/{tmdatagrid/components → components}/TMDataGridHeaderCell.module.css +12 -2
- package/src/{tmdatagrid/components → components}/TMDataGridHeaderCell.tsx +58 -21
- package/src/components/TMDataGridHeaderFilterRow.module.css +51 -0
- package/src/components/TMDataGridHeaderFilterRow.tsx +301 -0
- package/src/components/TMDataGridMenu.tsx +357 -0
- package/src/{tmdatagrid/components → components}/TMDataGridSelectColumn.tsx +11 -48
- package/src/{tmdatagrid/components → components}/TMDataGridTable.module.css +69 -56
- package/src/{tmdatagrid/components → components}/TMDataGridTable.tsx +240 -138
- package/src/{tmdatagrid/components → components}/TMDataGridToolbar.module.css +5 -0
- package/src/components/TMDataGridToolbar.tsx +181 -0
- package/src/{tmdatagrid/components → components}/editors/TMDataGridBooleanEditor.tsx +3 -3
- package/src/{tmdatagrid/components → components}/editors/TMDataGridDateEditor.tsx +3 -3
- package/src/{tmdatagrid/components → components}/editors/TMDataGridMultiSelectEditor.tsx +3 -3
- package/src/{tmdatagrid/components → components}/editors/TMDataGridNumberEditor.tsx +3 -3
- package/src/{tmdatagrid/components → components}/editors/TMDataGridSelectEditor.tsx +3 -3
- package/src/{tmdatagrid/components → components}/editors/TMDataGridStringEditor.tsx +3 -3
- package/src/{tmdatagrid/components → components}/editors/editorShared.ts +16 -2
- package/src/{tmdatagrid/components → components}/filters/DgAutocompleteFilter.tsx +5 -4
- package/src/{tmdatagrid/components → components}/filters/DgDateRangeFilter.tsx +22 -5
- package/src/{tmdatagrid/components → components}/filters/DgRangeSliderFilter.tsx +5 -1
- package/src/{tmdatagrid/components → components}/filters/DgTriStateFilter.tsx +5 -1
- package/src/{tmdatagrid/components → components}/filters/TMDataGridFilterValueInput.tsx +44 -28
- package/src/components/filters/controlLayout.ts +32 -0
- package/src/components/filters/filterControlFor.ts +65 -0
- package/src/components/generatedColumns.tsx +187 -0
- package/src/{tmdatagrid/components → components}/icons.ts +1 -0
- package/src/{tmdatagrid/components → components}/sticky.module.css +44 -0
- package/src/components/useHideableColumns.ts +52 -0
- package/src/{tmdatagrid/core → core}/autosize.ts +5 -2
- package/src/{tmdatagrid/core → core}/columnOptions.ts +60 -8
- package/src/{tmdatagrid/core → core}/columnOrdering.ts +33 -14
- package/src/{tmdatagrid/core → core}/columnUtils.ts +44 -5
- package/src/core/controlledStateSync.ts +108 -0
- package/src/core/deletedRows.ts +34 -0
- package/src/core/dom.ts +74 -0
- package/src/{tmdatagrid/core → core}/editEngine.ts +1107 -460
- package/src/core/export.ts +704 -0
- package/src/{tmdatagrid/core → core}/filterControls.ts +38 -1
- package/src/{tmdatagrid/core → core}/filterOperators.ts +64 -1
- package/src/core/filterSurface.ts +99 -0
- package/src/{tmdatagrid/core → core}/grouping.ts +21 -0
- package/src/{tmdatagrid/core → core}/labels.ts +51 -6
- package/src/{tmdatagrid/core → core}/labelsSv.ts +27 -6
- package/src/core/pageReset.ts +120 -0
- package/src/core/pagination.ts +81 -0
- package/src/{tmdatagrid/core → core}/persistence.ts +22 -5
- package/src/{tmdatagrid/core → core}/summary.ts +20 -4
- package/src/{tmdatagrid/index.ts → index.ts} +69 -35
- package/src/{tmdatagrid/useTMDataGrid.tsx → useTMDataGrid.tsx} +428 -109
- package/src/useTMDataGridExport.ts +78 -0
- package/src/tmdatagrid/components/TMDataGridFilterPanel.module.css +0 -35
- package/src/tmdatagrid/components/TMDataGridFilterPanel.tsx +0 -354
- package/src/tmdatagrid/components/TMDataGridToolbar.tsx +0 -161
- package/src/tmdatagrid/core/cellExport.ts +0 -320
- /package/src/{tmdatagrid/TMDataGridContext.ts → TMDataGridContext.ts} +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGrid.module.css +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGridDetailsColumn.module.css +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGridFilterPills.module.css +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGridFooter.module.css +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGridGroupColumn.module.css +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGridRowNumberColumn.tsx +0 -0
- /package/src/{tmdatagrid/components → components}/TMDataGridSearch.tsx +0 -0
- /package/src/{tmdatagrid/core → core}/capabilities.ts +0 -0
- /package/src/{tmdatagrid/core → core}/cellNavigation.ts +0 -0
- /package/src/{tmdatagrid/core → core}/cellRange.ts +0 -0
- /package/src/{tmdatagrid/core → core}/controlledState.ts +0 -0
- /package/src/{tmdatagrid/core → core}/draftCellContext.ts +0 -0
- /package/src/{tmdatagrid/core → core}/editorFocus.ts +0 -0
- /package/src/{tmdatagrid/core → core}/expanding.ts +0 -0
- /package/src/{tmdatagrid/core → core}/matchHighlight.ts +0 -0
- /package/src/{tmdatagrid/core → core}/quickSearch.ts +0 -0
- /package/src/{tmdatagrid/core → core}/resizePreview.ts +0 -0
- /package/src/{tmdatagrid/core → core}/rowPinning.ts +0 -0
- /package/src/{tmdatagrid/core → core}/rowSelection.ts +0 -0
- /package/src/{tmdatagrid/core → core}/sizes.ts +0 -0
- /package/src/{tmdatagrid/core → core}/useSettledTableState.ts +0 -0
|
@@ -5,24 +5,27 @@ description: >
|
|
|
5
5
|
xl) and what it drives, every --dg-* CSS variable for metrics, colours and the
|
|
6
6
|
stacking ladder, the two stylesheets styles.css and styles.layer.css and why
|
|
7
7
|
only one may be imported, the bounded-height layout rule with minHeight 0,
|
|
8
|
-
toolbar composition through children and TMDataGrid.Spacer,
|
|
8
|
+
toolbar composition through children and TMDataGrid.Spacer, Mantine BoxProps
|
|
9
|
+
(mb, px, hiddenFrom) and withBottomBorder on the toolbar, writing a toolbar
|
|
9
10
|
button with useTMDataGridContext, hiding it the way the built-ins do with
|
|
10
11
|
getGridCapabilities and getColumnCapabilities, why capabilities take a
|
|
11
12
|
features argument under the React Compiler, and localization through the
|
|
12
13
|
labels option, TMDATAGRID_LABELS_EN, TMDATAGRID_LABELS_SV, mergeLabels and
|
|
13
14
|
grid.labels. Load when styling or theming the grid, choosing a density,
|
|
14
|
-
building a toolbar, adding a button beside the built-in ones,
|
|
15
|
-
the
|
|
15
|
+
building a toolbar, adding a button beside the built-in ones, filling the grid
|
|
16
|
+
menu (TMDataGrid.Menu, the column chooser as menu items), or translating the
|
|
17
|
+
interface.
|
|
16
18
|
metadata:
|
|
17
19
|
type: core
|
|
18
20
|
library: '@jielga/tmdatagrid'
|
|
19
|
-
library_version: '2.0.
|
|
21
|
+
library_version: '2.0.1'
|
|
20
22
|
sources:
|
|
21
|
-
- 'Jielga/TMDataGrid:
|
|
22
|
-
- 'Jielga/TMDataGrid:
|
|
23
|
-
- 'Jielga/TMDataGrid:
|
|
24
|
-
- 'Jielga/TMDataGrid:
|
|
25
|
-
- 'Jielga/TMDataGrid:
|
|
23
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/docs/styling.md'
|
|
24
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/docs/toolbar.md'
|
|
25
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/docs/menu.md'
|
|
26
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/docs/localization.md'
|
|
27
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/src/core/capabilities.ts'
|
|
28
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/src/core/labels.ts'
|
|
26
29
|
---
|
|
27
30
|
|
|
28
31
|
# TMDataGrid - Appearance, toolbar and labels
|
|
@@ -118,7 +121,9 @@ element, and `TMDataGrid.Spacer` pushes what follows to the right.
|
|
|
118
121
|
<TMDataGrid.LoadingIndicator />
|
|
119
122
|
<ExportButton />
|
|
120
123
|
<TMDataGrid.FilterButton />
|
|
121
|
-
<TMDataGrid.
|
|
124
|
+
<TMDataGrid.Menu>
|
|
125
|
+
<TMDataGrid.Menu.Columns />
|
|
126
|
+
</TMDataGrid.Menu>
|
|
122
127
|
</TMDataGrid.Toolbar>
|
|
123
128
|
```
|
|
124
129
|
|
|
@@ -126,12 +131,60 @@ Each built-in renders nothing when its feature is off, so a read-only grid needs
|
|
|
126
131
|
no conditionals: `FilterButton` under `enableColumnFilters: false` renders
|
|
127
132
|
nothing at all.
|
|
128
133
|
|
|
134
|
+
`TMDataGrid.Toolbar` and `TMDataGrid.Spacer` take Mantine's `BoxProps` - the
|
|
135
|
+
style props (`mb`, `px`, `h`, `hiddenFrom`), `className`, `style` and `mod` -
|
|
136
|
+
set on the element itself. `withBottomBorder` on the toolbar draws a 1px line in
|
|
137
|
+
the theme's default border colour under it, the same line the header draws;
|
|
138
|
+
default `false`. `TMDataGrid.Footer`, `FilterPanel`, `FilterPills` and
|
|
139
|
+
`ColumnsPanel` take the same `BoxProps` on top of their own props.
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
<TMDataGrid.Toolbar withBottomBorder px="sm" mb="xs">
|
|
143
|
+
<TMDataGrid.SummaryCount />
|
|
144
|
+
<TMDataGrid.Spacer hiddenFrom="sm" />
|
|
145
|
+
<TMDataGrid.FilterButton />
|
|
146
|
+
</TMDataGrid.Toolbar>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### The grid menu
|
|
150
|
+
|
|
151
|
+
`TMDataGrid.Menu` is the burger: a Mantine `Menu` whose children are the
|
|
152
|
+
dropdown, so your own `Menu.Item`s sit beside the built-in items. It takes
|
|
153
|
+
Mantine `MenuProps` (defaults `position="bottom-end"`, `shadow="md"`,
|
|
154
|
+
`width={260}`, `withinPortal`), `icon` and `label` (default `labels.menuButton`).
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { Menu } from "@mantine/core";
|
|
158
|
+
|
|
159
|
+
<TMDataGrid.Menu>
|
|
160
|
+
<Menu.Item onClick={exportReport}>Export report</Menu.Item>
|
|
161
|
+
<Menu.Divider />
|
|
162
|
+
<Menu.Label>Columns</Menu.Label>
|
|
163
|
+
<TMDataGrid.Menu.Columns />
|
|
164
|
+
</TMDataGrid.Menu>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`TMDataGrid.Menu.Columns` is the column chooser as menu items: `Menu.Search`,
|
|
168
|
+
one checkbox item per hideable column, show/hide all and reset layout;
|
|
169
|
+
it renders nothing when no column can be hidden. Its pieces
|
|
170
|
+
`TMDataGrid.Menu.ColumnToggles` (`search` narrows the list),
|
|
171
|
+
`.ShowHideAll` and `.ResetLayout` are exported for menus that want only some of
|
|
172
|
+
them. Every piece needs a Mantine `Menu` around it and reads the grid from
|
|
173
|
+
context, so it works in any Mantine menu rendered inside `TMDataGrid`, and in a
|
|
174
|
+
`Menu.Sub` (pass `searchable={false}` there: `Menu.Search` registers on the
|
|
175
|
+
root menu and switches off its type-ahead and arrow keys).
|
|
176
|
+
|
|
177
|
+
The menu always renders, since it cannot see what its children render; a menu
|
|
178
|
+
holding only `Menu.Columns` should be hidden with `canHideAny` under
|
|
179
|
+
`enableHiding: false`. `TMDataGrid.ColumnsPanel` is the same chooser as plain
|
|
180
|
+
controls, for a Popover, a Drawer or an inline layout.
|
|
181
|
+
|
|
129
182
|
A button of your own reads the grid from context, which returns
|
|
130
183
|
`{ table, ui, features, labels, controlSize, resetSettings }`:
|
|
131
184
|
|
|
132
185
|
```tsx
|
|
133
186
|
import {
|
|
134
|
-
|
|
187
|
+
exportGrid,
|
|
135
188
|
getGridCapabilities,
|
|
136
189
|
useTMDataGridContext,
|
|
137
190
|
} from "@jielga/tmdatagrid";
|
|
@@ -143,7 +196,7 @@ function ExportButton() {
|
|
|
143
196
|
if (!canFilterAny) return null;
|
|
144
197
|
|
|
145
198
|
return (
|
|
146
|
-
<Button size={controlSize} onClick={() =>
|
|
199
|
+
<Button size={controlSize} onClick={() => void exportGrid({ table })}>
|
|
147
200
|
Export
|
|
148
201
|
</Button>
|
|
149
202
|
);
|
|
@@ -206,7 +259,7 @@ own uses the same strings as the built-in parts.
|
|
|
206
259
|
so an application that ordered its layers to put the grid underneath its own
|
|
207
260
|
overrides silently gets the opposite.
|
|
208
261
|
|
|
209
|
-
Source: `
|
|
262
|
+
Source: `packages/tmdatagrid/docs/styling.md` (The stylesheet).
|
|
210
263
|
|
|
211
264
|
### CRITICAL A grid with no bounded height
|
|
212
265
|
|
|
@@ -226,7 +279,7 @@ Correct:
|
|
|
226
279
|
<TMDataGrid {...grid} style={{ flex: 1, minHeight: 0 }} />
|
|
227
280
|
```
|
|
228
281
|
|
|
229
|
-
Source: `
|
|
282
|
+
Source: `packages/tmdatagrid/docs/styling.md` (Layout).
|
|
230
283
|
|
|
231
284
|
### HIGH Setting `--dg-row-height` to change density
|
|
232
285
|
|
|
@@ -241,7 +294,7 @@ Correct:
|
|
|
241
294
|
useTMDataGrid({ data, columns, meta: { rowHeight: 64 } });
|
|
242
295
|
```
|
|
243
296
|
|
|
244
|
-
Source: `
|
|
297
|
+
Source: `packages/tmdatagrid/docs/styling.md` (The size scale).
|
|
245
298
|
|
|
246
299
|
### HIGH A capability check without `features`
|
|
247
300
|
|
|
@@ -264,7 +317,7 @@ const { canSort } = getColumnCapabilities(column, features);
|
|
|
264
317
|
if (!canSort) return null;
|
|
265
318
|
```
|
|
266
319
|
|
|
267
|
-
Source: `
|
|
320
|
+
Source: `packages/tmdatagrid/docs/toolbar.md` (Why `features` is a second argument).
|
|
268
321
|
|
|
269
322
|
### MEDIUM An inline `labels` object
|
|
270
323
|
|
|
@@ -286,7 +339,7 @@ const labels = { noResults: "Inga träffar" } satisfies TMDataGridLabelsOverride
|
|
|
286
339
|
useTMDataGrid({ data, columns, labels });
|
|
287
340
|
```
|
|
288
341
|
|
|
289
|
-
Source: `
|
|
342
|
+
Source: `packages/tmdatagrid/docs/localization.md` (Keep the object stable).
|
|
290
343
|
|
|
291
344
|
### MEDIUM Conditionally rendering built-in toolbar parts
|
|
292
345
|
|
|
@@ -294,7 +347,7 @@ Each built-in already renders nothing when its feature is off. Wrapping them in
|
|
|
294
347
|
your own checks duplicates the capability logic, and the two drift apart the
|
|
295
348
|
first time an option changes.
|
|
296
349
|
|
|
297
|
-
Source: `
|
|
350
|
+
Source: `packages/tmdatagrid/docs/toolbar.md` (The built-in parts).
|
|
298
351
|
|
|
299
352
|
## Reference
|
|
300
353
|
|
|
@@ -306,7 +359,7 @@ Source: `src/docs/toolbar.md` (The built-in parts).
|
|
|
306
359
|
| `SIZE_ROW_HEIGHT` | Export | `Record<MantineSize, number>` | – | The row heights the scale table lists. |
|
|
307
360
|
| `SIZE_CONTROL_SIZE` | Export | `Record<MantineSize, MantineSize>` | – | Which control size each grid size uses. |
|
|
308
361
|
| `DEFAULT_TMDATAGRID_SIZE` | Export | `"md"` | – | The default size. |
|
|
309
|
-
| `TMDataGrid.Toolbar` · `Spacer` | Components | `children` |
|
|
362
|
+
| `TMDataGrid.Toolbar` · `Spacer` | Components | `children`, `withBottomBorder`, Mantine `BoxProps` | `withBottomBorder: false` | The flex row, and the push-right. Style props set on the element. |
|
|
310
363
|
| `useTMDataGridContext` | Hook | `() => TMDataGridContextValue` | – | `{ table, ui, features, labels, controlSize, resetSettings }`. |
|
|
311
364
|
| `getGridCapabilities` | Export | `(table, features) => TMDataGridCapabilities` | – | What this grid can do, reactively. |
|
|
312
365
|
| `getColumnCapabilities` | Export | `(column, features) => TMDataGridColumnCapabilities` | – | The same for one column. |
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cell-selection
|
|
3
3
|
description: >
|
|
4
|
-
Cell cursor, ranges
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
context menu
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
Cell cursor, ranges and the clipboard in TMDataGrid. Covers the cellSelection
|
|
5
|
+
option and its none / single / range modes, the keyboard map (arrows,
|
|
6
|
+
Shift+arrows, PageUp/PageDown, Home/End, Enter, F2, Escape, Space, Ctrl+C),
|
|
7
|
+
the one-tab-stop rule and the in-row Tab walk over controls inside cells, the
|
|
8
|
+
role flip from table/cell to grid/gridcell, ui.state.focusedCell and
|
|
9
|
+
ui.state.cellRange keyed by id, onFocusedCellChange, and the Copy / Export
|
|
10
|
+
cells / Include headers context menu that writes the rectangle in the grid's
|
|
11
|
+
exportOptions format. Load when adding keyboard cell navigation, selecting
|
|
12
|
+
blocks of cells, copying to a spreadsheet, or when Tab walks through controls
|
|
13
|
+
inside the grid body. Exporting whole rows is the data skill.
|
|
14
14
|
metadata:
|
|
15
15
|
type: core
|
|
16
16
|
library: '@jielga/tmdatagrid'
|
|
17
|
-
library_version: '2.0.
|
|
17
|
+
library_version: '2.0.1'
|
|
18
18
|
sources:
|
|
19
|
-
- 'Jielga/TMDataGrid:
|
|
20
|
-
- 'Jielga/TMDataGrid:
|
|
21
|
-
- 'Jielga/TMDataGrid:
|
|
22
|
-
- 'Jielga/TMDataGrid:
|
|
19
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/docs/cell-selection.md'
|
|
20
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/src/core/cellNavigation.ts'
|
|
21
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/src/core/cellRange.ts'
|
|
22
|
+
- 'Jielga/TMDataGrid:packages/tmdatagrid/src/core/export.ts'
|
|
23
23
|
---
|
|
24
24
|
|
|
25
25
|
# TMDataGrid - Cell selection
|
|
@@ -115,31 +115,33 @@ Ctrl+C puts the block on the clipboard as tab-separated text with CRLF between
|
|
|
115
115
|
rows, the format Excel, Sheets and Numbers all produce themselves. Values only:
|
|
116
116
|
Excel's own copy carries no header row either.
|
|
117
117
|
|
|
118
|
-
Right-clicking inside the selection opens Copy, "Export
|
|
118
|
+
Right-clicking inside the selection opens Copy, "Export cells" and an
|
|
119
119
|
"Include headers" toggle. A right-click outside it moves the selection there
|
|
120
120
|
first, the way a spreadsheet does. Your own `renderRowContextMenu` items are appended
|
|
121
121
|
below a divider, so nothing is lost by turning cell selection on.
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
"Export cells" writes the rectangle in the grid's export format - by default a
|
|
124
|
+
CSV for a Nordic Excel: a `sep=;` first line, a UTF-8 BOM, CRLF endings,
|
|
125
|
+
semicolons between fields and a comma as the decimal mark. The format, the file
|
|
126
|
+
name and the header row are the grid's `exportOptions`:
|
|
126
127
|
|
|
127
128
|
```tsx
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
const grid = useTMDataGrid({
|
|
130
|
+
data,
|
|
131
|
+
columns,
|
|
132
|
+
cellSelection: "range",
|
|
133
|
+
exportOptions: { format: csvFormat(), fileName: "employees" },
|
|
134
|
+
});
|
|
131
135
|
```
|
|
132
136
|
|
|
133
|
-
What gets written is the cell's **value**, not what it renders
|
|
134
|
-
|
|
137
|
+
What gets written is the cell's **value**, not what it renders, for the file and
|
|
138
|
+
for Ctrl+C alike; `meta.exportValue` substitutes a value and
|
|
139
|
+
`meta.enableExport: false` drops a column from both. Ctrl+C writes numbers with
|
|
140
|
+
the format's decimal mark, so what is pasted matches what is exported.
|
|
135
141
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
```tsx
|
|
141
|
-
<Button onClick={() => exportGridToCsv({ table: grid.table })}>Export</Button>
|
|
142
|
-
```
|
|
142
|
+
Exporting every filtered row rather than the rectangle is
|
|
143
|
+
`TMDataGrid.Menu.Export`, `TMDataGrid.Menu.ExportSelected` and
|
|
144
|
+
`useTMDataGridExport`, covered by the data skill.
|
|
143
145
|
|
|
144
146
|
## Common mistakes
|
|
145
147
|
|
|
@@ -166,7 +168,7 @@ Correct:
|
|
|
166
168
|
const OpenButton = ({ row }) => <Button onClick={() => open(row.id)}>Open</Button>;
|
|
167
169
|
```
|
|
168
170
|
|
|
169
|
-
Source: `
|
|
171
|
+
Source: `packages/tmdatagrid/docs/cell-selection.md` (One tab stop).
|
|
170
172
|
|
|
171
173
|
### HIGH Selectors written for `table` / `cell` roles
|
|
172
174
|
|
|
@@ -174,7 +176,7 @@ The grid reports `grid` and `gridcell` once cell selection is on, so a test or a
|
|
|
174
176
|
query written against `getByRole("cell")` stops resolving the moment the option
|
|
175
177
|
is set - including when `editing` turns it on implicitly.
|
|
176
178
|
|
|
177
|
-
Source: `
|
|
179
|
+
Source: `packages/tmdatagrid/docs/cell-selection.md`, and the `testing` skill.
|
|
178
180
|
|
|
179
181
|
### HIGH Reading the selection as row and column indices
|
|
180
182
|
|
|
@@ -189,41 +191,40 @@ const row = grid.table.getRow(focusedCell.rowId);
|
|
|
189
191
|
const value = row.getValue(focusedCell.columnId);
|
|
190
192
|
```
|
|
191
193
|
|
|
192
|
-
Source: `
|
|
194
|
+
Source: `packages/tmdatagrid/docs/cell-selection.md` (Where the selection lives).
|
|
193
195
|
|
|
194
196
|
### MEDIUM Expecting the export to match what the cells show
|
|
195
197
|
|
|
196
198
|
A cell renders React - often a badge, a link or a formatted string - and the
|
|
197
199
|
export writes the underlying value. A currency cell showing `32 000 kr` exports
|
|
198
|
-
`32000`.
|
|
199
|
-
if the file must match the screen.
|
|
200
|
+
`32000`. Set `meta.exportValue` on the column, or post-process the data from
|
|
201
|
+
`buildExportData`, if the file must match the screen.
|
|
200
202
|
|
|
201
|
-
Source: `
|
|
203
|
+
Source: `packages/tmdatagrid/docs/cell-selection.md` (The file).
|
|
202
204
|
|
|
203
205
|
### MEDIUM Expecting headers in the clipboard
|
|
204
206
|
|
|
205
207
|
Ctrl+C copies values only, matching Excel's own copy. Headers are an option of
|
|
206
|
-
the export menu and of `
|
|
208
|
+
the export menu and of `exportOptions`, not of the clipboard path.
|
|
207
209
|
|
|
208
|
-
Source: `
|
|
210
|
+
Source: `packages/tmdatagrid/docs/cell-selection.md` (Copy and export).
|
|
209
211
|
|
|
210
212
|
## Reference
|
|
211
213
|
|
|
212
214
|
| Name | Kind | Type | Default | What it does |
|
|
213
215
|
| --- | --- | --- | --- | --- |
|
|
214
|
-
| `cellSelection` | Option | `"none" \| "single" \| "range"` | `"none"`, or `"single"` under `editing` | Turns the cursor, and the rectangle, on. |
|
|
216
|
+
| `cellSelection` | Option | `TMDataGridCellSelectionMode`: `"none" \| "single" \| "range"` | `"none"`, or `"single"` under `editing` | Turns the cursor, and the rectangle, on. |
|
|
215
217
|
| `onFocusedCellChange` | Callback | `(cell \| null) => void` | – | Follows the cursor. |
|
|
216
|
-
| `
|
|
218
|
+
| `exportOptions` | Option | `TMDataGridExportOptions` | `DEFAULT_EXPORT_OPTIONS` | Format, file name and header row of the Export cells item. |
|
|
217
219
|
| `ui.state.focusedCell` | UI state | `{ rowId, columnId } \| null` | `null` | The cursor. |
|
|
218
220
|
| `ui.state.cellRange` | UI state | `{ anchor, focus } \| null` | `null` | The rectangle's two corners. |
|
|
219
221
|
| `ui.actions.setFocusedCell` · `setCellRange` | UI actions | – | – | Move either from your own code. |
|
|
220
|
-
| `
|
|
221
|
-
| `
|
|
222
|
-
| `
|
|
223
|
-
| `formatExportValue` | Export | `(value, options) => string` | – | One value, formatted as the
|
|
224
|
-
| `
|
|
225
|
-
| `
|
|
226
|
-
| `resolveRangeBounds` · `isWithinBounds` · `boundsEdges` · `boundsCellCount` | Exports | – | – | The rectangle arithmetic. |
|
|
222
|
+
| `buildExportData` | Export | `({ table, rows, bounds }) => TMDataGridExportData` | – | The rectangle's values, with `bounds`; the whole grid without. |
|
|
223
|
+
| `toClipboardText` · `writeClipboardText` | Exports | `(data, options?) => string` · `(text) => Promise<boolean>` | – | The pieces behind Ctrl+C: the tab-separated text, and the write that reports whether it landed. |
|
|
224
|
+
| `TMDataGridClipboardTextOptions` | Type | `{ decimalComma?, escapeFormulas? }` | `true` · `true` | The options of `toClipboardText`. |
|
|
225
|
+
| `formatExportValue` | Export | `(value, options) => string` | – | One value, formatted as the text formats would. |
|
|
226
|
+
| `resolveRangeBounds` | Export | `({ range, rowIndexOf, columnIndexOf }) => TMDataGridRangeBounds \| null` | – | The range as row and column indices - the `bounds` for `buildExportData`, over `getDisplayedRows`. |
|
|
227
|
+
| `ResolveRangeBoundsArgs` · `TMDataGridRangeBounds` | Types | – · `{ top, bottom, left, right }` | – | What `resolveRangeBounds` takes, and what it returns. |
|
|
227
228
|
| `data-focused` | Data attribute | – | – | On the focused cell. |
|
|
228
229
|
| `data-edge-top` · `-bottom` · `-left` · `-right` | Data attributes | – | – | On cells at the rectangle's border. |
|
|
229
230
|
|