react-glide-table 2.0.1 → 2.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 +70 -6
- package/dist/compound.cjs +532 -117
- package/dist/compound.d.cts +3 -3
- package/dist/compound.d.ts +3 -3
- package/dist/compound.js +513 -93
- package/dist/core.cjs +384 -1
- package/dist/core.d.cts +58 -6
- package/dist/core.d.ts +58 -6
- package/dist/core.js +382 -1
- package/dist/index.cjs +454 -25
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +436 -9
- package/dist/{types-DJOlsDL8.d.cts → types-CMUGtH-c.d.cts} +33 -1
- package/dist/{types-DJOlsDL8.d.ts → types-CMUGtH-c.d.ts} +33 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ export function Products({ data }: { data: Product[] }) {
|
|
|
74
74
|
| `slots.Pending` / `slots.Empty` | Loading and empty states |
|
|
75
75
|
| `className` / column `className` / `headerClassName` | Extra class hooks |
|
|
76
76
|
| `labels` / `summary` / `toolbar` | Copy and slot nodes |
|
|
77
|
-
| `Column.render`
|
|
77
|
+
| `Column.render` / `ColumnDef.cell` | Cell content custom render (prefer `update` via context) |
|
|
78
78
|
| `Column.kind` / `cellRenderers` | Built-in or custom cell kinds (override / add via registry) |
|
|
79
79
|
|
|
80
80
|
Row/cell **state** is exposed as `data-*` attributes for Tailwind variants:
|
|
@@ -105,7 +105,25 @@ Row-level UI → `slots.Row`. Cell content → `Column.render` or `Column.kind`.
|
|
|
105
105
|
|
|
106
106
|
`update` commits through `onCellChange` (preferred) or `onDataChange`. Prefer `update` over calling `setData` inside the render.
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
The same `update` is available on TanStack `ColumnDef.cell` when using `DataTable` directly (or `useGlideTable().getCellContext` with `flexRender`). Bare `cell.getContext()` does **not** include `update` at runtime — only the wrapped context does (`CellContextWithUpdate`).
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
const columns: ColumnDef<Product, unknown>[] = [
|
|
112
|
+
{
|
|
113
|
+
accessorKey: "status",
|
|
114
|
+
header: "Status",
|
|
115
|
+
cell: ({ getValue, update }) => (
|
|
116
|
+
<button type="button" onClick={() => update?.("done")}>
|
|
117
|
+
{String(getValue())}
|
|
118
|
+
</button>
|
|
119
|
+
),
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
<DataTable data={data} columns={columns} onCellChange={...} />
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Double-click inline editing (`editable` / `editType`) stays separate: use it for overlay text/number edits; use `render` / `cell` + `update` for always-visible controls.
|
|
109
127
|
|
|
110
128
|
### Cell kinds (`Column.kind` + `cellRenderers`)
|
|
111
129
|
|
|
@@ -148,15 +166,26 @@ type Product = { id: string; name: string; qty: number };
|
|
|
148
166
|
|
|
149
167
|
const columns: ColumnDef<Product, unknown>[] = [
|
|
150
168
|
{ accessorKey: "name", header: "Name" },
|
|
151
|
-
{
|
|
169
|
+
{
|
|
170
|
+
accessorKey: "qty",
|
|
171
|
+
header: "Qty",
|
|
172
|
+
cell: ({ getValue, update }) => (
|
|
173
|
+
<button type="button" onClick={() => update?.(Number(getValue()) + 1)}>
|
|
174
|
+
{String(getValue())}
|
|
175
|
+
</button>
|
|
176
|
+
),
|
|
177
|
+
},
|
|
152
178
|
];
|
|
153
179
|
|
|
154
180
|
export function ProductTable({ data }: { data: Product[] }) {
|
|
155
|
-
const { table, rows, scrollRef } = useGlideTable({
|
|
181
|
+
const { table, rows, scrollRef, getCellContext } = useGlideTable({
|
|
156
182
|
data,
|
|
157
183
|
columns,
|
|
158
184
|
getRowId: (row) => row.id,
|
|
159
185
|
rowSelectionMode: "multi",
|
|
186
|
+
onCellChange: (rowId, columnId, value) => {
|
|
187
|
+
/* update your data */
|
|
188
|
+
},
|
|
160
189
|
});
|
|
161
190
|
|
|
162
191
|
return (
|
|
@@ -183,7 +212,7 @@ export function ProductTable({ data }: { data: Product[] }) {
|
|
|
183
212
|
<tr key={row.id}>
|
|
184
213
|
{row.getVisibleCells().map((cell) => (
|
|
185
214
|
<td key={cell.id}>
|
|
186
|
-
{flexRender(cell.column.columnDef.cell, cell
|
|
215
|
+
{flexRender(cell.column.columnDef.cell, getCellContext(cell))}
|
|
187
216
|
</td>
|
|
188
217
|
))}
|
|
189
218
|
</tr>
|
|
@@ -195,7 +224,7 @@ export function ProductTable({ data }: { data: Product[] }) {
|
|
|
195
224
|
}
|
|
196
225
|
```
|
|
197
226
|
|
|
198
|
-
Wire `rowContextValue` into your own row/cell components for edit, selection, expand, and row-span behavior.
|
|
227
|
+
Wire `rowContextValue` into your own row/cell components for edit, selection, expand, and row-span behavior. Use `getCellContext(cell)` (not bare `cell.getContext()`) so `ColumnDef.cell` receives `update`.
|
|
199
228
|
|
|
200
229
|
## Clipboard copy & paste
|
|
201
230
|
|
|
@@ -262,6 +291,41 @@ Opt in with `enableColumnResize`. Drag the handle on the right edge of a header
|
|
|
262
291
|
| `Column.resizable={false}` | Disable resize for one column |
|
|
263
292
|
| `classNames.resizeHandle` | Style hook for the drag handle |
|
|
264
293
|
|
|
294
|
+
## Column reorder
|
|
295
|
+
|
|
296
|
+
Opt in with `enableColumnReorder`. Drag a column header to a new position; a drop edge marks the insert point ([demo](https://glideapps.github.io/glide-data-grid/?path=/story/glide-data-grid-dataeditor-demos--rearrange-columns)). Movement below a small threshold still counts as a click, so sortable headers keep working. The resize handle does not start a reorder.
|
|
297
|
+
|
|
298
|
+
Leaf columns can move across `ColumnGroup`s. Consecutive leaves that still share a group stay wrapped; interleaved leaves split that group (Glide-style). Frozen columns keep their freeze after the move.
|
|
299
|
+
|
|
300
|
+
```tsx
|
|
301
|
+
<ProductTable
|
|
302
|
+
data={data}
|
|
303
|
+
enableColumnReorder
|
|
304
|
+
// optional controlled order (leaf column ids)
|
|
305
|
+
// columnOrder={order}
|
|
306
|
+
// onColumnOrderChange={setOrder}
|
|
307
|
+
>
|
|
308
|
+
<ProductTable.Header>
|
|
309
|
+
<ProductTable.Column field="name" width={200}>
|
|
310
|
+
Name
|
|
311
|
+
</ProductTable.Column>
|
|
312
|
+
<ProductTable.Column field="sku" reorderable={false}>
|
|
313
|
+
SKU
|
|
314
|
+
</ProductTable.Column>
|
|
315
|
+
</ProductTable.Header>
|
|
316
|
+
</ProductTable>
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
| Prop | Role |
|
|
320
|
+
| --------------------------------------- | ------------------------------------------------- |
|
|
321
|
+
| `enableColumnReorder` | Turn on header drag reorder (default `false`) |
|
|
322
|
+
| `columnOrder` / `onColumnOrderChange` | Controlled leaf id list (`string[]`) |
|
|
323
|
+
| `Column.reorderable={false}` | Disable drag for one column (still a drop target) |
|
|
324
|
+
| `data-reorderable` / `data-drop-edge` | Drag / drop state hooks on header cells |
|
|
325
|
+
| `classNames.dropEdge` | Extra class while a drop edge is shown |
|
|
326
|
+
|
|
327
|
+
Helpers (`/core`): `applyLeafColumnOrder`, `moveColumnIds`, `collectLeafColumnIds`, `useColumnReorder`, …
|
|
328
|
+
|
|
265
329
|
## Column freeze
|
|
266
330
|
|
|
267
331
|
Opt in with `enableColumnFreeze`. Mark columns with `frozen` — sticky insets are stacked so frozen cells never overlap, and **column order is unchanged** (middle columns may also freeze).
|