react-glide-table 1.0.2 → 1.1.0
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 +60 -493
- package/dist/index.cjs +736 -1229
- package/dist/index.d.cts +337 -68
- package/dist/index.d.ts +337 -68
- package/dist/index.js +699 -1211
- package/package.json +10 -4
- package/dist/style.css +0 -404
package/README.md
CHANGED
|
@@ -1,56 +1,8 @@
|
|
|
1
1
|
# react-glide-table
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless React table primitives built on [@tanstack/react-table](https://tanstack.com/table) and [@tanstack/react-virtual](https://tanstack.com/virtual).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Inspired by Glide Data Grid
|
|
8
|
-
|
|
9
|
-
[Glide Data Grid](https://github.com/glideapps/glide-data-grid) (`@glideapps/glide-data-grid`) is a Canvas-based spreadsheet-style grid. This library is **not** a wrapper around it — it reimplements the basic interaction patterns on top of a normal HTML `<table>` + TanStack stack, so you keep DOM accessibility, CSS styling, and a React-friendly column API.
|
|
10
|
-
|
|
11
|
-
### Glide-inspired capabilities layered in
|
|
12
|
-
|
|
13
|
-
| Capability | What Glide provides | How `react-glide-table` adopts it |
|
|
14
|
-
| --- | --- | --- |
|
|
15
|
-
| **Cell range selection** | Drag / keyboard ranges (`gridSelection`, `rangeSelect`) | Click a cell, drag across cells to select a rectangular range |
|
|
16
|
-
| **Fill handle** | `fillHandle` — copy values into adjacent cells | Selection corner handle fills neighboring cells; commits via `onDataChange` |
|
|
17
|
-
| **Inline editing** | Built-in double-click edit with commit / cancel | Double-click editable cells; **Enter** commits, **Escape** cancels (`editable` / `editType`) |
|
|
18
|
-
| **Row selection** | `rowSelect`: none / single / multi | `rowSelectionMode`: `"none"` \| `"single"` \| `"multi"` (controlled or uncontrolled) |
|
|
19
|
-
| **Large-list scrolling** | Canvas lazy paint for millions of rows | DOM **row virtualization** via `@tanstack/react-virtual` (spacer rows inside `<tbody>`) |
|
|
20
|
-
| **Merged cells** | Span / merge support | `enableRowSpan` + column `rowSpan` / `rowSpanKey` for consecutive vertical merges |
|
|
21
|
-
|
|
22
|
-
### Intentionally different from Glide
|
|
23
|
-
|
|
24
|
-
- **Rendering**: HTML table DOM instead of HTML5 Canvas — easier theming, custom React cell renderers, and standard CSS.
|
|
25
|
-
- **Column model**: TanStack `ColumnDef` or declarative `Table.Column` / `createTable`, not Glide’s canvas cell draw API.
|
|
26
|
-
- **Extra app-table features** (beyond the Glide interaction set): compound components, sorting, controlled pagination, toolbar slots, and tree / expandable rows.
|
|
27
|
-
|
|
28
|
-
### Not ported (yet)
|
|
29
|
-
|
|
30
|
-
These Glide features are **not** included: Canvas custom cell drawing, frozen/pinned columns, column reorder / resize as first-class APIs, multi-rect / column-range selection stacks, markdown / bubble / image / sparkline cell types, and million-row Canvas-level scale. Use this library when you want Glide-like **edit / select / fill** UX on a conventional React table.
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
|
|
34
|
-
- **Declarative columns** via `Table` / `createTable` compound components
|
|
35
|
-
- **Low-level API** via `DataTable` + TanStack `ColumnDef`
|
|
36
|
-
- **Row virtualization** (HTML table + spacer rows; disabled automatically when row spanning is on)
|
|
37
|
-
- **Row selection** — none / single / multi *(Glide-inspired)*
|
|
38
|
-
- **Inline cell editing** — double-click to edit (`text` | `number`) *(Glide-inspired)*
|
|
39
|
-
- **Cell range selection & fill handle** — drag to select, fill adjacent cells (Excel-like) *(Glide-inspired)*
|
|
40
|
-
- **Row spanning** — merge consecutive cells by key *(Glide-inspired)*
|
|
41
|
-
- **Tree / expandable rows** — nested or flat parent–child data
|
|
42
|
-
- **Sorting** — clickable headers through `Table.Column sortable`
|
|
43
|
-
- **Pagination** — controlled `Table.Pagination`
|
|
44
|
-
- **Toolbar slots** — counts, summary, custom actions
|
|
45
|
-
|
|
46
|
-
## Requirements
|
|
47
|
-
|
|
48
|
-
| Package | Version | Notes |
|
|
49
|
-
| --- | --- | --- |
|
|
50
|
-
| `react` | `^18` or `^19` | Peer dependency — provided by your app |
|
|
51
|
-
| `react-dom` | `^18` or `^19` | Peer dependency — provided by your app |
|
|
52
|
-
|
|
53
|
-
`@tanstack/react-table` and `@tanstack/react-virtual` are installed automatically with this package.
|
|
5
|
+
You own the markup and styles. This package exposes state, handlers, and pure helpers for selection, editing, fill, row spanning, tree expand, and virtualization.
|
|
54
6
|
|
|
55
7
|
## Installation
|
|
56
8
|
|
|
@@ -58,476 +10,91 @@ These Glide features are **not** included: Canvas custom cell drawing, frozen/pi
|
|
|
58
10
|
npm install react-glide-table
|
|
59
11
|
# or
|
|
60
12
|
pnpm add react-glide-table
|
|
61
|
-
# or
|
|
62
|
-
yarn add react-glide-table
|
|
63
13
|
```
|
|
64
14
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import "react-glide-table/style.css"
|
|
69
|
-
```
|
|
15
|
+
Peer dependencies: `react` and `react-dom` (`^18` or `^19`).
|
|
70
16
|
|
|
71
17
|
## Quick start
|
|
72
18
|
|
|
73
|
-
### Recommended: typed compound table with `createTable`
|
|
74
|
-
|
|
75
|
-
`createTable<T>()` returns a typed compound component (`Header`, `Column`, `Body`, `Pagination`) so `field` and `render` stay type-safe.
|
|
76
|
-
|
|
77
19
|
```tsx
|
|
78
|
-
import {
|
|
79
|
-
import {
|
|
80
|
-
import "react-glide-table
|
|
81
|
-
|
|
82
|
-
type Product = {
|
|
83
|
-
id: string
|
|
84
|
-
name: string
|
|
85
|
-
qty: number
|
|
86
|
-
price: number
|
|
87
|
-
}
|
|
20
|
+
import { flexRender } from "@tanstack/react-table"
|
|
21
|
+
import { useGlideTable } from "react-glide-table"
|
|
22
|
+
import type { ColumnDef } from "react-glide-table"
|
|
88
23
|
|
|
89
|
-
|
|
24
|
+
type Product = { id: string; name: string; qty: number }
|
|
90
25
|
|
|
91
|
-
const
|
|
92
|
-
{
|
|
93
|
-
{
|
|
26
|
+
const columns: ColumnDef<Product, unknown>[] = [
|
|
27
|
+
{ accessorKey: "name", header: "Name" },
|
|
28
|
+
{ accessorKey: "qty", header: "Qty" },
|
|
94
29
|
]
|
|
95
30
|
|
|
96
|
-
export function
|
|
97
|
-
const
|
|
31
|
+
export function ProductTable({ data }: { data: Product[] }) {
|
|
32
|
+
const { table, rows, scrollRef } = useGlideTable({
|
|
33
|
+
data,
|
|
34
|
+
columns,
|
|
35
|
+
getRowId: (row) => row.id,
|
|
36
|
+
rowSelectionMode: "multi",
|
|
37
|
+
})
|
|
98
38
|
|
|
99
39
|
return (
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
40
|
+
<div ref={scrollRef}>
|
|
41
|
+
<table>
|
|
42
|
+
<thead>
|
|
43
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
44
|
+
<tr key={headerGroup.id}>
|
|
45
|
+
{headerGroup.headers.map((header) => (
|
|
46
|
+
<th key={header.id}>
|
|
47
|
+
{header.isPlaceholder
|
|
48
|
+
? null
|
|
49
|
+
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
50
|
+
</th>
|
|
51
|
+
))}
|
|
52
|
+
</tr>
|
|
53
|
+
))}
|
|
54
|
+
</thead>
|
|
55
|
+
<tbody>
|
|
56
|
+
{rows.map((row) => (
|
|
57
|
+
<tr key={row.id}>
|
|
58
|
+
{row.getVisibleCells().map((cell) => (
|
|
59
|
+
<td key={cell.id}>
|
|
60
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
61
|
+
</td>
|
|
62
|
+
))}
|
|
63
|
+
</tr>
|
|
64
|
+
))}
|
|
65
|
+
</tbody>
|
|
66
|
+
</table>
|
|
67
|
+
</div>
|
|
125
68
|
)
|
|
126
69
|
}
|
|
127
70
|
```
|
|
128
71
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
```tsx
|
|
132
|
-
import { Table } from "react-glide-table"
|
|
133
|
-
|
|
134
|
-
<Table data={rows} getRowId={(row) => String(row.id)}>
|
|
135
|
-
<Table.Header>
|
|
136
|
-
<Table.Column field="name">Name</Table.Column>
|
|
137
|
-
<Table.Column field="amount" sortable>
|
|
138
|
-
Amount
|
|
139
|
-
</Table.Column>
|
|
140
|
-
</Table.Header>
|
|
141
|
-
</Table>
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Low-level: `DataTable` + `ColumnDef`
|
|
145
|
-
|
|
146
|
-
Use this when you already build TanStack column definitions yourself.
|
|
147
|
-
|
|
148
|
-
```tsx
|
|
149
|
-
import { DataTable, type ColumnDef } from "react-glide-table"
|
|
150
|
-
|
|
151
|
-
type Row = { id: string; name: string; amount: number }
|
|
152
|
-
|
|
153
|
-
const columns: ColumnDef<Row, unknown>[] = [
|
|
154
|
-
{ id: "name", accessorKey: "name", header: "Name" },
|
|
155
|
-
{
|
|
156
|
-
id: "amount",
|
|
157
|
-
accessorKey: "amount",
|
|
158
|
-
header: "Amount",
|
|
159
|
-
meta: { align: "right", editable: true, editType: "number" },
|
|
160
|
-
},
|
|
161
|
-
]
|
|
72
|
+
Wire `rowContextValue` into your own row/cell components for edit, selection, expand, and row-span behavior. See the `playground/` app for a full reference UI built on top of `useGlideTable`.
|
|
162
73
|
|
|
163
|
-
|
|
164
|
-
```
|
|
74
|
+
## Public API
|
|
165
75
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
## APIs
|
|
169
|
-
|
|
170
|
-
### `createTable<T>()` / `Table`
|
|
171
|
-
|
|
172
|
-
Compound wrapper around `DataTable`. It:
|
|
173
|
-
|
|
174
|
-
1. Reads `Table.Column` children inside `Table.Header` and builds column defs
|
|
175
|
-
2. Applies client-side sorting when a column is `sortable`
|
|
176
|
-
3. Applies client-side pagination when `Table.Pagination` is present
|
|
177
|
-
4. Forwards the rest of the props to `DataTable`
|
|
178
|
-
|
|
179
|
-
| Subcomponent | Role |
|
|
76
|
+
| Export | Role |
|
|
180
77
|
| --- | --- |
|
|
181
|
-
| `
|
|
182
|
-
| `
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
185
|
-
|
|
186
|
-
> Always put at least one `Table.Column` inside `Table.Header`.
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
### `Table.Column` props
|
|
191
|
-
|
|
192
|
-
| Prop | Type | Default | Description |
|
|
193
|
-
| --- | --- | --- | --- |
|
|
194
|
-
| `field` | `string` | — | Column id / accessor key |
|
|
195
|
-
| `virtual` | `boolean` | `false` | If `true`, no `accessorKey` (for checkbox / index columns) |
|
|
196
|
-
| `children` | `ReactNode` | — | Header label |
|
|
197
|
-
| `sortable` | `boolean` | `false` | Clickable sort header (asc → desc → clear) |
|
|
198
|
-
| `width` | `number` | `150` | Column width (px) |
|
|
199
|
-
| `align` | `"left" \| "center" \| "right"` | — | Cell / header alignment |
|
|
200
|
-
| `rowSpan` | `boolean` | — | Enable vertical merge for this column |
|
|
201
|
-
| `rowSpanKey` | `string` | column `field` | Field used to decide merge groups |
|
|
202
|
-
| `editable` | `boolean` | — | Double-click to edit |
|
|
203
|
-
| `editType` | `"text" \| "number"` | `"text"` | Input type while editing |
|
|
204
|
-
| `className` | `string` | — | Body cell class |
|
|
205
|
-
| `headerClassName` | `string` | — | Header cell class |
|
|
206
|
-
| `render` | `(value, row, index) => ReactNode` | — | Custom cell renderer |
|
|
207
|
-
|
|
208
|
-
---
|
|
209
|
-
|
|
210
|
-
### Shared table props (`Table` / `DataTable`)
|
|
211
|
-
|
|
212
|
-
All of these (except `columns` / `children`) work on both APIs.
|
|
213
|
-
|
|
214
|
-
#### Data & identity
|
|
215
|
-
|
|
216
|
-
| Prop | Type | Default | Description |
|
|
217
|
-
| --- | --- | --- | --- |
|
|
218
|
-
| `data` | `T[]` | — | Row data |
|
|
219
|
-
| `getRowId` | `(row, index) => string` | index as string | Stable row id (recommended) |
|
|
220
|
-
| `columns` | `ColumnDef[]` | — | **`DataTable` only** |
|
|
221
|
-
| `children` | `ReactNode` | — | **`Table` only** — Header / Pagination |
|
|
222
|
-
| `onDataChange` | `(data: T[]) => void` | — | Called after cell edit or fill |
|
|
223
|
-
|
|
224
|
-
#### Loading & empty
|
|
225
|
-
|
|
226
|
-
| Prop | Type | Default | Description |
|
|
227
|
-
| --- | --- | --- | --- |
|
|
228
|
-
| `isPending` | `boolean` | `false` | Shows a loading placeholder instead of the table |
|
|
229
|
-
| `emptyText` | `string` | `"데이터가 없습니다."` | Message when there are no rows |
|
|
230
|
-
| `className` | `string` | — | Root class name |
|
|
78
|
+
| `useGlideTable` | Headless table engine (TanStack instance, virtualization, selection/edit/expand state) |
|
|
79
|
+
| `useCellEdit` / `useCellSelection` / `useConvertTreeData` | Feature hooks |
|
|
80
|
+
| `applyCellEdit`, `applyFillData`, `buildColumnRowSpanMap`, … | Pure helpers |
|
|
81
|
+
| `DEFAULT_DATA_TABLE_LABELS` / `resolveDataTableLabels` | Optional English UI copy helpers |
|
|
82
|
+
| Tree field defaults | `id` / `parentId` / `children` / `qty` |
|
|
231
83
|
|
|
232
|
-
|
|
84
|
+
## Notable constraints
|
|
233
85
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
| `totalCount` | `number` | Total count before filter (shown as `/ N`) |
|
|
237
|
-
| `filteredCount` | `number` | Current visible count (defaults to current data length) |
|
|
238
|
-
| `summary` | `ReactNode` | Left-side summary slot |
|
|
239
|
-
| `toolbar` | `ReactNode` | Right-side actions (export, delete, …) |
|
|
240
|
-
| `selectionLabel` | `(count) => ReactNode` | Custom selection label (default: `"N개 선택됨"`) |
|
|
86
|
+
- **Row span + virtualization**: when `enableRowSpan` is on, virtualization is forced off (HTML `<table>` + `rowspan` cannot safely share a virtual window).
|
|
87
|
+
- **No shipped CSS / opinionated components**: bring your own DOM. The published package does not export the reference UI components under `src/components/ui` (but some feature helpers are re-exported and shipped).
|
|
241
88
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
| Prop | Type | Default | Description |
|
|
245
|
-
| --- | --- | --- | --- |
|
|
246
|
-
| `rowSelectionMode` | `"none" \| "single" \| "multi"` | `"none"` | Selection mode |
|
|
247
|
-
| `rowSelection` | `RowSelectionState` | — | Controlled selection map (`{ [rowId]: true }`) |
|
|
248
|
-
| `onRowSelectionChange` | `(updater) => void` | — | Controlled selection updater |
|
|
249
|
-
| `getRowCanSelect` | `(row, index) => boolean` | all selectable | Return `false` to disable selection for a row |
|
|
250
|
-
| `selectOnRowClick` | `boolean` | `true` | If `false`, only checkbox / explicit controls select |
|
|
251
|
-
| `preserveRowSelection` | `boolean` | `false` | If `true`, clicking a selected row does not deselect it |
|
|
252
|
-
| `onRowClick` | `(row, index) => void` | — | Extra row click handler |
|
|
253
|
-
| `getRowClassName` | `(row, index) => string \| undefined` | — | Per-row class names |
|
|
254
|
-
|
|
255
|
-
```tsx
|
|
256
|
-
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
|
257
|
-
|
|
258
|
-
<ProductTable
|
|
259
|
-
data={data}
|
|
260
|
-
getRowId={(row) => row.id}
|
|
261
|
-
rowSelectionMode="multi"
|
|
262
|
-
rowSelection={rowSelection}
|
|
263
|
-
onRowSelectionChange={setRowSelection}
|
|
264
|
-
getRowCanSelect={(row) => row.qty > 0}
|
|
265
|
-
selectOnRowClick={false}
|
|
266
|
-
/>
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
#### Row spanning
|
|
270
|
-
|
|
271
|
-
| Prop | Type | Default | Description |
|
|
272
|
-
| --- | --- | --- | --- |
|
|
273
|
-
| `enableRowSpan` | `boolean` | `false` | Turn on vertical cell merge |
|
|
274
|
-
|
|
275
|
-
Mark columns with `rowSpan` (and optionally `rowSpanKey`):
|
|
276
|
-
|
|
277
|
-
```tsx
|
|
278
|
-
<ProductTable data={rows} enableRowSpan getRowId={(r) => r.id}>
|
|
279
|
-
<ProductTable.Header>
|
|
280
|
-
<ProductTable.Column field="group" rowSpan rowSpanKey="groupId">
|
|
281
|
-
Group
|
|
282
|
-
</ProductTable.Column>
|
|
283
|
-
<ProductTable.Column field="name">Name</ProductTable.Column>
|
|
284
|
-
</ProductTable.Header>
|
|
285
|
-
</ProductTable>
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
> When `enableRowSpan` is `true`, virtualization is **forced off** so merged cells stay correct.
|
|
289
|
-
|
|
290
|
-
#### Tree / expandable rows
|
|
291
|
-
|
|
292
|
-
Enable expand UI by setting `toggleField`. Nested children are read from `flattenField` (default `assemblyMaterials`). Flat parent links use `childField` (default `assemblyCode`).
|
|
293
|
-
|
|
294
|
-
| Prop | Type | Default | Description |
|
|
295
|
-
| --- | --- | --- | --- |
|
|
296
|
-
| `toggleField` | `string` | — | Key used as expand id (e.g. `materialCode`). Presence enables tree mode |
|
|
297
|
-
| `childField` | `string` | `"assemblyCode"` | Parent reference field for flat trees |
|
|
298
|
-
| `flattenField` | `string` | `"assemblyMaterials"` | Nested children array field |
|
|
299
|
-
| `expandedRows` | `Set<string>` | — | Controlled expanded keys |
|
|
300
|
-
| `onExpandedRowsChange` | `(next: Set<string>) => void` | — | Controlled expand updater |
|
|
301
|
-
| `preventExpand` | `boolean` | `false` | Always show children; hide toggle |
|
|
302
|
-
|
|
303
|
-
```tsx
|
|
304
|
-
type BomRow = {
|
|
305
|
-
id: string
|
|
306
|
-
materialCode: string
|
|
307
|
-
materialName: string
|
|
308
|
-
assemblyMaterials?: BomRow[]
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const [expandedRows, setExpandedRows] = useState<Set<string>>(() => new Set())
|
|
312
|
-
|
|
313
|
-
<Table
|
|
314
|
-
data={bom}
|
|
315
|
-
toggleField="materialCode"
|
|
316
|
-
flattenField="assemblyMaterials"
|
|
317
|
-
expandedRows={expandedRows}
|
|
318
|
-
onExpandedRowsChange={setExpandedRows}
|
|
319
|
-
getRowId={(row) => row.id}
|
|
320
|
-
>
|
|
321
|
-
<Table.Header>
|
|
322
|
-
<Table.Column field="materialCode">Code</Table.Column>
|
|
323
|
-
<Table.Column field="materialName">Name</Table.Column>
|
|
324
|
-
</Table.Header>
|
|
325
|
-
</Table>
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
On first load, root rows with children are expanded by default.
|
|
329
|
-
|
|
330
|
-
#### Virtualization
|
|
331
|
-
|
|
332
|
-
| Prop | Type | Default | Description |
|
|
333
|
-
| --- | --- | --- | --- |
|
|
334
|
-
| `enableVirtualization` | `boolean` | `true` | Virtualize body rows for large lists |
|
|
335
|
-
| `estimateRowHeight` | `number` | `44` | Estimated row height (px); measured and corrected at runtime |
|
|
336
|
-
| `virtualOverscan` | `number` | `8` | Extra rows rendered above/below the viewport |
|
|
337
|
-
|
|
338
|
-
```tsx
|
|
339
|
-
<ProductTable
|
|
340
|
-
data={largeDataset}
|
|
341
|
-
enableVirtualization
|
|
342
|
-
estimateRowHeight={44}
|
|
343
|
-
virtualOverscan={12}
|
|
344
|
-
getRowId={(row) => row.id}
|
|
345
|
-
>
|
|
346
|
-
...
|
|
347
|
-
</ProductTable>
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
---
|
|
351
|
-
|
|
352
|
-
## Sorting
|
|
353
|
-
|
|
354
|
-
Set `sortable` on a column. Click cycle: **ascending → descending → unsorted**.
|
|
355
|
-
|
|
356
|
-
Sorting is applied client-side inside `Table` / `createTable` before pagination.
|
|
357
|
-
|
|
358
|
-
```tsx
|
|
359
|
-
<ProductTable.Column field="name" sortable>
|
|
360
|
-
Name
|
|
361
|
-
</ProductTable.Column>
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
---
|
|
365
|
-
|
|
366
|
-
## Pagination
|
|
367
|
-
|
|
368
|
-
`Table.Pagination` is **controlled**. Pass `page`, `onChange`, and usually `pageSize` / `totalCount`.
|
|
369
|
-
|
|
370
|
-
The table slices `data` client-side to the current page. The toolbar still uses `filteredCount` / `totalCount` for the full dataset size.
|
|
371
|
-
|
|
372
|
-
```tsx
|
|
373
|
-
const [page, setPage] = useState(1)
|
|
374
|
-
|
|
375
|
-
<ProductTable
|
|
376
|
-
data={allRows}
|
|
377
|
-
filteredCount={allRows.length}
|
|
378
|
-
totalCount={allRows.length}
|
|
379
|
-
getRowId={(row) => row.id}
|
|
380
|
-
>
|
|
381
|
-
<ProductTable.Header>
|
|
382
|
-
<ProductTable.Column field="name">Name</ProductTable.Column>
|
|
383
|
-
</ProductTable.Header>
|
|
384
|
-
<ProductTable.Pagination
|
|
385
|
-
page={page}
|
|
386
|
-
pageSize={10}
|
|
387
|
-
totalCount={allRows.length}
|
|
388
|
-
onChange={setPage}
|
|
389
|
-
/>
|
|
390
|
-
</ProductTable>
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
| Prop | Type | Default | Description |
|
|
394
|
-
| --- | --- | --- | --- |
|
|
395
|
-
| `page` | `number` | — | Current page (1-based) |
|
|
396
|
-
| `pageSize` | `number` | `10` | Rows per page |
|
|
397
|
-
| `totalCount` | `number` | `0` | Total items for page math |
|
|
398
|
-
| `onChange` | `(page: number) => void` | — | Page change handler |
|
|
399
|
-
| `className` | `string` | — | Wrapper class |
|
|
400
|
-
|
|
401
|
-
For server-side pagination, pass only the current page’s `data` and set `totalCount` / `filteredCount` from the server; keep `page` / `onChange` in sync with your fetch.
|
|
402
|
-
|
|
403
|
-
---
|
|
404
|
-
|
|
405
|
-
## Inline editing
|
|
406
|
-
|
|
407
|
-
1. Mark a column with `editable` (and optional `editType`)
|
|
408
|
-
2. Provide `onDataChange` so edits update your state
|
|
409
|
-
3. **Double-click** a cell to edit
|
|
410
|
-
4. Press **Enter** to commit, **Escape** to cancel
|
|
411
|
-
|
|
412
|
-
```tsx
|
|
413
|
-
const [data, setData] = useState(rows)
|
|
414
|
-
|
|
415
|
-
<ProductTable data={data} onDataChange={setData} getRowId={(r) => r.id}>
|
|
416
|
-
<ProductTable.Header>
|
|
417
|
-
<ProductTable.Column field="name" editable editType="text">
|
|
418
|
-
Name
|
|
419
|
-
</ProductTable.Column>
|
|
420
|
-
<ProductTable.Column field="qty" editable editType="number">
|
|
421
|
-
Qty
|
|
422
|
-
</ProductTable.Column>
|
|
423
|
-
</ProductTable.Header>
|
|
424
|
-
</ProductTable>
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
With `DataTable`, set the same flags on `columnDef.meta`:
|
|
428
|
-
|
|
429
|
-
```ts
|
|
430
|
-
meta: { editable: true, editType: "number" }
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
---
|
|
434
|
-
|
|
435
|
-
## Cell selection & fill
|
|
436
|
-
|
|
437
|
-
When `onDataChange` is provided, users can:
|
|
438
|
-
|
|
439
|
-
1. Click a cell to select it
|
|
440
|
-
2. Drag across cells to select a range
|
|
441
|
-
3. Use the fill handle on the selection to copy values into adjacent cells
|
|
442
|
-
|
|
443
|
-
This mirrors spreadsheet-style fill behavior. Keep `data` controlled via `onDataChange`.
|
|
444
|
-
|
|
445
|
-
---
|
|
446
|
-
|
|
447
|
-
## Column meta (`DataTable` / TanStack)
|
|
448
|
-
|
|
449
|
-
When using `DataTable` directly, configure columns through TanStack `ColumnDef` and `meta`:
|
|
450
|
-
|
|
451
|
-
```ts
|
|
452
|
-
import type { ColumnDef } from "react-glide-table"
|
|
453
|
-
|
|
454
|
-
const columns: ColumnDef<Row, unknown>[] = [
|
|
455
|
-
{
|
|
456
|
-
id: "name",
|
|
457
|
-
accessorKey: "name",
|
|
458
|
-
header: "Name",
|
|
459
|
-
size: 200,
|
|
460
|
-
meta: {
|
|
461
|
-
align: "left",
|
|
462
|
-
editable: true,
|
|
463
|
-
editType: "text",
|
|
464
|
-
rowSpan: false,
|
|
465
|
-
className: "my-cell",
|
|
466
|
-
headerClassName: "my-header",
|
|
467
|
-
},
|
|
468
|
-
},
|
|
469
|
-
]
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
| `meta` key | Type | Description |
|
|
473
|
-
| --- | --- | --- |
|
|
474
|
-
| `align` | `"left" \| "center" \| "right"` | Alignment |
|
|
475
|
-
| `className` | `string` | Body cell class |
|
|
476
|
-
| `headerClassName` | `string` | Header class |
|
|
477
|
-
| `editable` | `boolean` | Inline edit |
|
|
478
|
-
| `editType` | `"text" \| "number"` | Edit input type |
|
|
479
|
-
| `rowSpan` | `boolean` | Vertical merge |
|
|
480
|
-
| `rowSpanKey` | `string` | Merge key field |
|
|
481
|
-
|
|
482
|
-
---
|
|
483
|
-
|
|
484
|
-
## Exports
|
|
485
|
-
|
|
486
|
-
```ts
|
|
487
|
-
import {
|
|
488
|
-
createTable,
|
|
489
|
-
Table,
|
|
490
|
-
DataTable,
|
|
491
|
-
type TableCompoundComponent,
|
|
492
|
-
type TableProps,
|
|
493
|
-
type TableColumnProps,
|
|
494
|
-
type DataTableProps,
|
|
495
|
-
type ColumnDef,
|
|
496
|
-
type RowSelectionState,
|
|
497
|
-
type RowSelectionMode,
|
|
498
|
-
} from "react-glide-table"
|
|
499
|
-
|
|
500
|
-
import "react-glide-table/style.css"
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
---
|
|
504
|
-
|
|
505
|
-
## Tips
|
|
506
|
-
|
|
507
|
-
1. **Always pass `getRowId`** for stable selection, expand, and edit behavior when rows reorder or paginate.
|
|
508
|
-
2. Prefer **`createTable<YourRowType>()`** for end-to-end TypeScript safety.
|
|
509
|
-
3. Import **`react-glide-table/style.css`** or the table will be unstyled.
|
|
510
|
-
4. Prefer **virtualization on** for large lists; turn **`enableRowSpan` off** if you need virtualization.
|
|
511
|
-
5. Keep **`data` immutable** when handling `onDataChange` (replace the array / row objects).
|
|
512
|
-
6. For checkbox-only selection, set **`selectOnRowClick={false}`** and render a virtual checkbox column with your own UI if needed.
|
|
513
|
-
|
|
514
|
-
---
|
|
515
|
-
|
|
516
|
-
## Development
|
|
89
|
+
## Local playground
|
|
517
90
|
|
|
518
91
|
```bash
|
|
519
92
|
pnpm install
|
|
520
|
-
pnpm
|
|
93
|
+
pnpm dev
|
|
521
94
|
```
|
|
522
95
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
- `dist/index.js` / `dist/index.cjs` — ESM / CJS bundles
|
|
526
|
-
- `dist/index.d.ts` — TypeScript declarations
|
|
527
|
-
- `dist/style.css` — bundled styles (`react-glide-table/style.css`)
|
|
528
|
-
|
|
529
|
-
---
|
|
96
|
+
The playground imports a reference `createTable` / `DataTable` UI from the repo source to exercise the headless core.
|
|
530
97
|
|
|
531
98
|
## License
|
|
532
99
|
|
|
533
|
-
|
|
100
|
+
MIT
|