@tanstack/vue-table 9.0.0-beta.5 → 9.0.0-beta.51
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 +2 -0
- package/dist/FlexRender.cjs +2 -3
- package/dist/FlexRender.cjs.map +1 -1
- package/dist/FlexRender.js +2 -3
- package/dist/FlexRender.js.map +1 -1
- package/dist/createTableHook.cjs +4 -9
- package/dist/createTableHook.cjs.map +1 -1
- package/dist/createTableHook.d.cts +39 -12
- package/dist/createTableHook.d.ts +39 -12
- package/dist/createTableHook.js +4 -9
- package/dist/createTableHook.js.map +1 -1
- package/dist/experimental-worker-plugin.cjs +9 -0
- package/dist/experimental-worker-plugin.d.cts +1 -0
- package/dist/experimental-worker-plugin.d.ts +1 -0
- package/dist/experimental-worker-plugin.js +3 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/reactivity.cjs +2 -6
- package/dist/reactivity.cjs.map +1 -1
- package/dist/reactivity.js +2 -6
- package/dist/reactivity.js.map +1 -1
- package/dist/useTable.cjs +3 -7
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.d.cts +1 -8
- package/dist/useTable.d.ts +1 -8
- package/dist/useTable.js +3 -7
- package/dist/useTable.js.map +1 -1
- package/package.json +8 -4
- package/skills/create-table-hook/SKILL.md +146 -0
- package/skills/getting-started/SKILL.md +144 -0
- package/skills/migrate-v8-to-v9/SKILL.md +185 -0
- package/skills/table-state/SKILL.md +191 -0
- package/skills/with-tanstack-query/SKILL.md +127 -0
- package/skills/with-tanstack-virtual/SKILL.md +116 -0
- package/src/createTableHook.ts +108 -17
- package/src/experimental-worker-plugin.ts +1 -0
- package/src/reactivity.ts +1 -2
- package/src/useTable.ts +3 -11
- package/skills/vue/client-to-server/SKILL.md +0 -365
- package/skills/vue/compose-with-tanstack-form/SKILL.md +0 -369
- package/skills/vue/compose-with-tanstack-pacer/SKILL.md +0 -318
- package/skills/vue/compose-with-tanstack-query/SKILL.md +0 -385
- package/skills/vue/compose-with-tanstack-store/SKILL.md +0 -301
- package/skills/vue/compose-with-tanstack-virtual/SKILL.md +0 -340
- package/skills/vue/getting-started/SKILL.md +0 -409
- package/skills/vue/migrate-v8-to-v9/SKILL.md +0 -375
- package/skills/vue/production-readiness/SKILL.md +0 -271
- package/skills/vue/table-state/SKILL.md +0 -403
package/src/createTableHook.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { mergeProxy } from './merge-proxy'
|
|
|
5
5
|
import { useTable } from './useTable'
|
|
6
6
|
import type { TableOptionsWithReactiveData, VueTable } from './useTable'
|
|
7
7
|
import type { FlexRenderCell, FlexRenderHeader } from './FlexRender'
|
|
8
|
-
import type { Component, InjectionKey, PropType
|
|
8
|
+
import type { Component, InjectionKey, PropType } from 'vue'
|
|
9
9
|
import type {
|
|
10
10
|
AccessorFn,
|
|
11
11
|
AccessorFnColumnDef,
|
|
@@ -26,7 +26,6 @@ import type {
|
|
|
26
26
|
RowData,
|
|
27
27
|
Table,
|
|
28
28
|
TableFeatures,
|
|
29
|
-
TableState,
|
|
30
29
|
} from '@tanstack/table-core'
|
|
31
30
|
|
|
32
31
|
export type ComponentType<T extends Record<string, any>> = Component<T>
|
|
@@ -213,10 +212,9 @@ export interface AppHeaderProps<
|
|
|
213
212
|
export type AppVueTable<
|
|
214
213
|
TFeatures extends TableFeatures,
|
|
215
214
|
TData extends RowData,
|
|
216
|
-
TSelected,
|
|
217
215
|
TTableComponents extends Record<string, ComponentType<any>>,
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
_TCellComponents extends Record<string, ComponentType<any>>,
|
|
217
|
+
_THeaderComponents extends Record<string, ComponentType<any>>,
|
|
220
218
|
> = VueTable<TFeatures, TData> &
|
|
221
219
|
NoInfer<TTableComponents> & {
|
|
222
220
|
AppTable: Component<AppTableProps>
|
|
@@ -226,6 +224,75 @@ export type AppVueTable<
|
|
|
226
224
|
FlexRender: typeof AppFlexRender
|
|
227
225
|
}
|
|
228
226
|
|
|
227
|
+
export interface CreateTableHookResult<
|
|
228
|
+
TFeatures extends TableFeatures,
|
|
229
|
+
TTableComponents extends Record<string, ComponentType<any>>,
|
|
230
|
+
TCellComponents extends Record<string, ComponentType<any>>,
|
|
231
|
+
THeaderComponents extends Record<string, ComponentType<any>>,
|
|
232
|
+
> {
|
|
233
|
+
/** The features object that was passed to `createTableHook`. */
|
|
234
|
+
appFeatures: TFeatures
|
|
235
|
+
/**
|
|
236
|
+
* A column helper pre-bound to `TFeatures` and the registered components, so
|
|
237
|
+
* the cell/header/footer render props expose the bound components.
|
|
238
|
+
*/
|
|
239
|
+
createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<
|
|
240
|
+
TFeatures,
|
|
241
|
+
TData,
|
|
242
|
+
TCellComponents,
|
|
243
|
+
THeaderComponents
|
|
244
|
+
>
|
|
245
|
+
/**
|
|
246
|
+
* Creates a table with the `App*` wrapper components and registered
|
|
247
|
+
* `tableComponents` attached. `TData` is inferred from the `data` option.
|
|
248
|
+
*/
|
|
249
|
+
useAppTable: <TData extends RowData>(
|
|
250
|
+
tableOptions: Omit<
|
|
251
|
+
TableOptionsWithReactiveData<TFeatures, TData>,
|
|
252
|
+
'features'
|
|
253
|
+
>,
|
|
254
|
+
) => AppVueTable<
|
|
255
|
+
TFeatures,
|
|
256
|
+
TData,
|
|
257
|
+
TTableComponents,
|
|
258
|
+
TCellComponents,
|
|
259
|
+
THeaderComponents
|
|
260
|
+
>
|
|
261
|
+
/**
|
|
262
|
+
* Reads the table provided by the nearest `<table.AppTable>`. This is the same
|
|
263
|
+
* extended instance `useAppTable` returns, so the `App*` components and your
|
|
264
|
+
* `tableComponents` are available on it.
|
|
265
|
+
*/
|
|
266
|
+
useTableContext: <TData extends RowData = RowData>() => AppVueTable<
|
|
267
|
+
TFeatures,
|
|
268
|
+
TData,
|
|
269
|
+
TTableComponents,
|
|
270
|
+
TCellComponents,
|
|
271
|
+
THeaderComponents
|
|
272
|
+
>
|
|
273
|
+
/**
|
|
274
|
+
* Reads the cell provided by the nearest `<table.AppCell>`, extended with your
|
|
275
|
+
* `cellComponents` and a context-bound `FlexRender`.
|
|
276
|
+
*/
|
|
277
|
+
useCellContext: <TValue extends CellData = CellData>() => Cell<
|
|
278
|
+
TFeatures,
|
|
279
|
+
any,
|
|
280
|
+
TValue
|
|
281
|
+
> &
|
|
282
|
+
TCellComponents & { FlexRender: Component }
|
|
283
|
+
/**
|
|
284
|
+
* Reads the header provided by the nearest `<table.AppHeader>` /
|
|
285
|
+
* `<table.AppFooter>`, extended with your `headerComponents` and a
|
|
286
|
+
* context-bound `FlexRender`.
|
|
287
|
+
*/
|
|
288
|
+
useHeaderContext: <TValue extends CellData = CellData>() => Header<
|
|
289
|
+
TFeatures,
|
|
290
|
+
any,
|
|
291
|
+
TValue
|
|
292
|
+
> &
|
|
293
|
+
THeaderComponents & { FlexRender: Component }
|
|
294
|
+
}
|
|
295
|
+
|
|
229
296
|
export const AppFlexRender = defineComponent({
|
|
230
297
|
name: 'TableFlexRender',
|
|
231
298
|
props: {
|
|
@@ -281,7 +348,6 @@ export const AppFlexRender = defineComponent({
|
|
|
281
348
|
* ```ts
|
|
282
349
|
* const { useAppTable, createAppColumnHelper } = createTableHook({
|
|
283
350
|
* features,
|
|
284
|
-
* rowModels: {},
|
|
285
351
|
* tableComponents: {},
|
|
286
352
|
* cellComponents: {},
|
|
287
353
|
* headerComponents: {},
|
|
@@ -303,7 +369,12 @@ export function createTableHook<
|
|
|
303
369
|
TTableComponents,
|
|
304
370
|
TCellComponents,
|
|
305
371
|
THeaderComponents
|
|
306
|
-
>)
|
|
372
|
+
>): CreateTableHookResult<
|
|
373
|
+
TFeatures,
|
|
374
|
+
TTableComponents,
|
|
375
|
+
TCellComponents,
|
|
376
|
+
THeaderComponents
|
|
377
|
+
> {
|
|
307
378
|
const TableContext = Symbol('TableContext') as InjectionKey<
|
|
308
379
|
VueTable<TFeatures, any>
|
|
309
380
|
>
|
|
@@ -328,9 +399,12 @@ export function createTableHook<
|
|
|
328
399
|
>
|
|
329
400
|
}
|
|
330
401
|
|
|
331
|
-
function useTableContext<TData extends RowData = RowData>():
|
|
402
|
+
function useTableContext<TData extends RowData = RowData>(): AppVueTable<
|
|
332
403
|
TFeatures,
|
|
333
|
-
TData
|
|
404
|
+
TData,
|
|
405
|
+
TTableComponents,
|
|
406
|
+
TCellComponents,
|
|
407
|
+
THeaderComponents
|
|
334
408
|
> {
|
|
335
409
|
const table = inject(TableContext)
|
|
336
410
|
|
|
@@ -341,14 +415,24 @@ export function createTableHook<
|
|
|
341
415
|
)
|
|
342
416
|
}
|
|
343
417
|
|
|
344
|
-
|
|
418
|
+
// The value provided by `<table.AppTable>` is the extended table (the App*
|
|
419
|
+
// wrapper components and `tableComponents` are Object.assign-ed onto the same
|
|
420
|
+
// instance `useAppTable` returns), so this asserts the runtime shape.
|
|
421
|
+
return table as unknown as AppVueTable<
|
|
422
|
+
TFeatures,
|
|
423
|
+
TData,
|
|
424
|
+
TTableComponents,
|
|
425
|
+
TCellComponents,
|
|
426
|
+
THeaderComponents
|
|
427
|
+
>
|
|
345
428
|
}
|
|
346
429
|
|
|
347
430
|
function useCellContext<TValue extends CellData = CellData>(): Cell<
|
|
348
431
|
TFeatures,
|
|
349
432
|
any,
|
|
350
433
|
TValue
|
|
351
|
-
>
|
|
434
|
+
> &
|
|
435
|
+
TCellComponents & { FlexRender: Component } {
|
|
352
436
|
const cell = inject(CellContext)
|
|
353
437
|
|
|
354
438
|
if (!cell) {
|
|
@@ -358,14 +442,18 @@ export function createTableHook<
|
|
|
358
442
|
)
|
|
359
443
|
}
|
|
360
444
|
|
|
361
|
-
|
|
445
|
+
// `<table.AppCell>` Object.assign-es `cellComponents` and `FlexRender` onto
|
|
446
|
+
// the same cell instance it provides, so this asserts the runtime shape.
|
|
447
|
+
return cell as unknown as Cell<TFeatures, any, TValue> &
|
|
448
|
+
TCellComponents & { FlexRender: Component }
|
|
362
449
|
}
|
|
363
450
|
|
|
364
451
|
function useHeaderContext<TValue extends CellData = CellData>(): Header<
|
|
365
452
|
TFeatures,
|
|
366
453
|
any,
|
|
367
454
|
TValue
|
|
368
|
-
>
|
|
455
|
+
> &
|
|
456
|
+
THeaderComponents & { FlexRender: Component } {
|
|
369
457
|
const header = inject(HeaderContext)
|
|
370
458
|
|
|
371
459
|
if (!header) {
|
|
@@ -374,7 +462,10 @@ export function createTableHook<
|
|
|
374
462
|
)
|
|
375
463
|
}
|
|
376
464
|
|
|
377
|
-
|
|
465
|
+
// `<table.AppHeader>` / `<table.AppFooter>` Object.assign `headerComponents`
|
|
466
|
+
// and `FlexRender` onto the same header instance they provide.
|
|
467
|
+
return header as unknown as Header<TFeatures, any, TValue> &
|
|
468
|
+
THeaderComponents & { FlexRender: Component }
|
|
378
469
|
}
|
|
379
470
|
|
|
380
471
|
const CellFlexRender = defineComponent({
|
|
@@ -404,12 +495,11 @@ export function createTableHook<
|
|
|
404
495
|
function useAppTable<TData extends RowData>(
|
|
405
496
|
tableOptions: Omit<
|
|
406
497
|
TableOptionsWithReactiveData<TFeatures, TData>,
|
|
407
|
-
'features'
|
|
498
|
+
'features'
|
|
408
499
|
>,
|
|
409
500
|
): AppVueTable<
|
|
410
501
|
TFeatures,
|
|
411
502
|
TData,
|
|
412
|
-
TableState<TFeatures>,
|
|
413
503
|
TTableComponents,
|
|
414
504
|
TCellComponents,
|
|
415
505
|
THeaderComponents
|
|
@@ -516,7 +606,6 @@ export function createTableHook<
|
|
|
516
606
|
}) as AppVueTable<
|
|
517
607
|
TFeatures,
|
|
518
608
|
TData,
|
|
519
|
-
TableState<TFeatures>,
|
|
520
609
|
TTableComponents,
|
|
521
610
|
TCellComponents,
|
|
522
611
|
THeaderComponents
|
|
@@ -524,6 +613,8 @@ export function createTableHook<
|
|
|
524
613
|
}
|
|
525
614
|
|
|
526
615
|
return {
|
|
616
|
+
// `TableOptionsWithReactiveData` widens `features` to allow a reactive ref,
|
|
617
|
+
// so this narrows it back to the resolved `TFeatures` for `appFeatures`.
|
|
527
618
|
appFeatures: defaultTableOptions.features as TFeatures,
|
|
528
619
|
createAppColumnHelper,
|
|
529
620
|
useAppTable,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/table-core/experimental-worker-plugin'
|
package/src/reactivity.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { computed, shallowRef, watch } from 'vue'
|
|
2
|
-
import { batch } from '@tanstack/store'
|
|
3
2
|
import type {
|
|
4
3
|
TableAtomOptions,
|
|
5
4
|
TableReactivityBindings,
|
|
@@ -84,6 +83,6 @@ export function vueReactivity(): TableReactivityBindings {
|
|
|
84
83
|
return refToWritableAtom(shallowRef(value) as ShallowRef<T>)
|
|
85
84
|
},
|
|
86
85
|
untrack: (fn) => fn(),
|
|
87
|
-
batch,
|
|
86
|
+
batch: (fn) => fn(),
|
|
88
87
|
}
|
|
89
88
|
}
|
package/src/useTable.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
Table,
|
|
8
8
|
TableFeatures,
|
|
9
9
|
TableOptions,
|
|
10
|
-
TableState,
|
|
11
10
|
} from '@tanstack/table-core'
|
|
12
11
|
import type { MaybeRef, VNode } from 'vue'
|
|
13
12
|
|
|
@@ -47,13 +46,7 @@ function getReactiveOptionDeps<
|
|
|
47
46
|
export type VueTable<
|
|
48
47
|
TFeatures extends TableFeatures,
|
|
49
48
|
TData extends RowData,
|
|
50
|
-
> =
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated Prefer `table.atoms.<slice>.get()` for slice snapshots, or
|
|
53
|
-
* `table.Subscribe` for explicit subscriptions. `table.store.state` is a
|
|
54
|
-
* current-value snapshot and is easy to misuse in render code.
|
|
55
|
-
*/
|
|
56
|
-
readonly store: Table<TFeatures, TData>['store']
|
|
49
|
+
> = Table<TFeatures, TData> & {
|
|
57
50
|
/** Creates a reactive render boundary. The child function reads the table
|
|
58
51
|
* atoms it needs, so Vue only tracks those atom reads.
|
|
59
52
|
*/
|
|
@@ -75,7 +68,6 @@ export type VueTable<
|
|
|
75
68
|
* const table = useTable(
|
|
76
69
|
* {
|
|
77
70
|
* features,
|
|
78
|
-
* rowModels: {},
|
|
79
71
|
* columns,
|
|
80
72
|
* data,
|
|
81
73
|
* },
|
|
@@ -103,7 +95,7 @@ export function useTable<
|
|
|
103
95
|
|
|
104
96
|
const mergedOptions = mergeProxy(tableOptions, {
|
|
105
97
|
features: {
|
|
106
|
-
|
|
98
|
+
coreReactivityFeature: reactivity,
|
|
107
99
|
...(unref(tableOptions.features) ?? {}),
|
|
108
100
|
},
|
|
109
101
|
}) as TableOptionsWithReactiveData<TFeatures, TData>
|
|
@@ -174,7 +166,7 @@ export function useTable<
|
|
|
174
166
|
table.Subscribe = (props: {
|
|
175
167
|
children: (atoms: Table<TFeatures, TData>['atoms']) => VNode | Array<VNode>
|
|
176
168
|
}) => {
|
|
177
|
-
return props.children(table.atoms)
|
|
169
|
+
return props.children(table.atoms as Table<TFeatures, TData>['atoms'])
|
|
178
170
|
}
|
|
179
171
|
|
|
180
172
|
return table
|
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: vue/client-to-server
|
|
3
|
-
description: >
|
|
4
|
-
Convert a client-side `@tanstack/vue-table` to server-side. Set `manualPagination` /
|
|
5
|
-
`manualSorting` / `manualFiltering` / `manualGrouping` / `manualExpanding` for whichever
|
|
6
|
-
slices the server owns; drop the matching `rowModels` factories (don't ship
|
|
7
|
-
`paginatedRowModel` when the server paginates); supply `rowCount` so `table.getPageCount()`
|
|
8
|
-
works; own the relevant state slices via either external atoms (`@tanstack/vue-store`
|
|
9
|
-
`createAtom` + `options.atoms`) or `state` + `on[State]Change` with getter wrappers. Key any
|
|
10
|
-
data fetch (TanStack Query / fetch / rxResource alternative) on the controlled state and use
|
|
11
|
-
`placeholderData: keepPreviousData` (or equivalent) to avoid a 0-rows flash between pages.
|
|
12
|
-
type: lifecycle
|
|
13
|
-
library: tanstack-table
|
|
14
|
-
framework: vue
|
|
15
|
-
library_version: '9.0.0-alpha.48'
|
|
16
|
-
requires:
|
|
17
|
-
- state-management
|
|
18
|
-
- pagination
|
|
19
|
-
- filtering
|
|
20
|
-
- sorting
|
|
21
|
-
sources:
|
|
22
|
-
- examples/vue/basic-external-atoms/
|
|
23
|
-
- examples/vue/basic-external-state/
|
|
24
|
-
- examples/vue/with-tanstack-query/
|
|
25
|
-
- docs/framework/vue/guide/table-state.md
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
# Client-to-Server Conversion (Vue)
|
|
29
|
-
|
|
30
|
-
## Dependencies
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pnpm add @tanstack/vue-table @tanstack/vue-store
|
|
34
|
-
# Recommended fetch layer:
|
|
35
|
-
pnpm add @tanstack/vue-query
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
External atoms (`@tanstack/vue-store`) are recommended for server-managed slices. They cut the
|
|
39
|
-
`on[State]Change` plumbing entirely — the table writes to the atom; the query keys on the atom.
|
|
40
|
-
|
|
41
|
-
## Setup — minimal server-paginated table
|
|
42
|
-
|
|
43
|
-
```vue
|
|
44
|
-
<script setup lang="ts">
|
|
45
|
-
import { computed, ref, watchEffect } from 'vue'
|
|
46
|
-
import { createAtom, useSelector } from '@tanstack/vue-store'
|
|
47
|
-
import { keepPreviousData, useQuery } from '@tanstack/vue-query'
|
|
48
|
-
import {
|
|
49
|
-
FlexRender,
|
|
50
|
-
createColumnHelper,
|
|
51
|
-
rowPaginationFeature,
|
|
52
|
-
tableFeatures,
|
|
53
|
-
useTable,
|
|
54
|
-
type PaginationState,
|
|
55
|
-
} from '@tanstack/vue-table'
|
|
56
|
-
import { fetchPeople } from './api'
|
|
57
|
-
|
|
58
|
-
type Person = { firstName: string; lastName: string; age: number }
|
|
59
|
-
|
|
60
|
-
const features = tableFeatures({ rowPaginationFeature })
|
|
61
|
-
const columnHelper = createColumnHelper<typeof features, Person>()
|
|
62
|
-
const columns = columnHelper.columns([
|
|
63
|
-
columnHelper.accessor('firstName', { header: 'First' }),
|
|
64
|
-
columnHelper.accessor('lastName', { header: 'Last' }),
|
|
65
|
-
columnHelper.accessor('age', { header: 'Age' }),
|
|
66
|
-
])
|
|
67
|
-
|
|
68
|
-
// 1) Own pagination in an external atom. Cheap for the table to write through.
|
|
69
|
-
const paginationAtom = createAtom<PaginationState>({
|
|
70
|
-
pageIndex: 0,
|
|
71
|
-
pageSize: 10,
|
|
72
|
-
})
|
|
73
|
-
const pagination = useSelector(paginationAtom)
|
|
74
|
-
|
|
75
|
-
// 2) Key the query on the atom value. table.setPageIndex(...) writes to the atom
|
|
76
|
-
// → useSelector re-evaluates → useQuery refetches.
|
|
77
|
-
const dataQuery = useQuery(() => ({
|
|
78
|
-
queryKey: ['people', pagination.value],
|
|
79
|
-
queryFn: () => fetchPeople(pagination.value),
|
|
80
|
-
placeholderData: keepPreviousData, // avoid "0 rows" flash between pages
|
|
81
|
-
}))
|
|
82
|
-
|
|
83
|
-
const tableData = computed<Person[]>(() => dataQuery.data.value?.rows ?? [])
|
|
84
|
-
const rowCount = ref(0)
|
|
85
|
-
watchEffect(() => {
|
|
86
|
-
const next = dataQuery.data.value?.rowCount
|
|
87
|
-
if (next != null) rowCount.value = next // keep last known total for pager UI
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// 3) Manual pagination + `rowCount`. NO paginatedRowModel in `rowModels` — server paginates.
|
|
91
|
-
const table = useTable({
|
|
92
|
-
features,
|
|
93
|
-
rowModels: {},
|
|
94
|
-
columns,
|
|
95
|
-
data: tableData,
|
|
96
|
-
rowCount,
|
|
97
|
-
atoms: { pagination: paginationAtom },
|
|
98
|
-
manualPagination: true,
|
|
99
|
-
})
|
|
100
|
-
</script>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Source: `examples/vue/with-tanstack-query/src/App.tsx`, `examples/vue/basic-external-atoms/`.
|
|
104
|
-
|
|
105
|
-
## Core Patterns
|
|
106
|
-
|
|
107
|
-
### 1. The `manual*` flag + `rowModels` drop pair
|
|
108
|
-
|
|
109
|
-
Pick which slices live server-side and flip the matching `manual*` flag. **Also drop the
|
|
110
|
-
matching `rowModels` factory** — otherwise the table re-processes server-processed rows.
|
|
111
|
-
|
|
112
|
-
| Server owns | Set | Drop from `rowModels` |
|
|
113
|
-
| ----------- | ------------------------ | --------------------- |
|
|
114
|
-
| Pagination | `manualPagination: true` | `paginatedRowModel` |
|
|
115
|
-
| Sorting | `manualSorting: true` | `sortedRowModel` |
|
|
116
|
-
| Filtering | `manualFiltering: true` | `filteredRowModel` |
|
|
117
|
-
| Grouping | `manualGrouping: true` | `groupedRowModel` |
|
|
118
|
-
| Expanding | `manualExpanding: true` | `expandedRowModel` |
|
|
119
|
-
|
|
120
|
-
Column visibility / ordering / pinning / row selection are client-side state and stay as-is.
|
|
121
|
-
|
|
122
|
-
### 2. `rowCount` so `getPageCount()` works
|
|
123
|
-
|
|
124
|
-
Without `rowCount`, `getPageCount()` falls back to `Math.ceil(data.length / pageSize)` — i.e.
|
|
125
|
-
`1` if the server already paginated. The pager locks at "Page 1 of 1".
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
useTable({
|
|
129
|
-
features,
|
|
130
|
-
rowModels: {},
|
|
131
|
-
columns,
|
|
132
|
-
data: tableData,
|
|
133
|
-
rowCount: dataQuery.data.value?.rowCount, // or a stable ref/computed
|
|
134
|
-
atoms: { pagination: paginationAtom },
|
|
135
|
-
manualPagination: true,
|
|
136
|
-
})
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
If `rowCount` isn't immediately available, hold the last known value in a `ref` and update via
|
|
140
|
-
`watchEffect` so the pager doesn't reset to 0 during refetches.
|
|
141
|
-
|
|
142
|
-
### 3. Two state-ownership shapes (pick one per slice)
|
|
143
|
-
|
|
144
|
-
**External atoms (recommended with Query).** Table writes through to the atom. No
|
|
145
|
-
`on[State]Change` needed.
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
const paginationAtom = createAtom<PaginationState>({
|
|
149
|
-
pageIndex: 0,
|
|
150
|
-
pageSize: 10,
|
|
151
|
-
})
|
|
152
|
-
useTable({
|
|
153
|
-
features,
|
|
154
|
-
rowModels: {},
|
|
155
|
-
columns,
|
|
156
|
-
data,
|
|
157
|
-
rowCount,
|
|
158
|
-
atoms: { pagination: paginationAtom },
|
|
159
|
-
manualPagination: true,
|
|
160
|
-
})
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**Classic `state` + `on[State]Change` with getters.** Required when migrating from v8 or
|
|
164
|
-
integrating with existing Vue ref-based state. Each slice must be a getter so Vue tracks
|
|
165
|
-
`.value`.
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
const pagination = ref<PaginationState>({ pageIndex: 0, pageSize: 10 })
|
|
169
|
-
|
|
170
|
-
useTable({
|
|
171
|
-
features,
|
|
172
|
-
rowModels: {},
|
|
173
|
-
columns,
|
|
174
|
-
data,
|
|
175
|
-
rowCount,
|
|
176
|
-
state: {
|
|
177
|
-
get pagination() {
|
|
178
|
-
return pagination.value
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
onPaginationChange: (u) => {
|
|
182
|
-
pagination.value = typeof u === 'function' ? u(pagination.value) : u
|
|
183
|
-
},
|
|
184
|
-
manualPagination: true,
|
|
185
|
-
})
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
**Precedence:** `atoms[slice]` > `state[slice]` > internal `baseAtoms[slice]`. Don't pass the
|
|
189
|
-
same slice through both — the atoms wins silently.
|
|
190
|
-
|
|
191
|
-
### 4. Cache keys must include controlled state
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
const sortingAtom = createAtom<SortingState>([])
|
|
195
|
-
const paginationAtom = createAtom<PaginationState>({
|
|
196
|
-
pageIndex: 0,
|
|
197
|
-
pageSize: 10,
|
|
198
|
-
})
|
|
199
|
-
const sorting = useSelector(sortingAtom)
|
|
200
|
-
const pagination = useSelector(paginationAtom)
|
|
201
|
-
|
|
202
|
-
const dataQuery = useQuery(() => ({
|
|
203
|
-
queryKey: [
|
|
204
|
-
'people',
|
|
205
|
-
{ sorting: sorting.value, pagination: pagination.value },
|
|
206
|
-
],
|
|
207
|
-
queryFn: () =>
|
|
208
|
-
fetchPeople({ sorting: sorting.value, pagination: pagination.value }),
|
|
209
|
-
placeholderData: keepPreviousData,
|
|
210
|
-
}))
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
If pagination/sort/filter aren't in `queryKey`, Query won't refetch when the user clicks a
|
|
214
|
-
pager button — the buttons "do nothing" from the user's POV.
|
|
215
|
-
|
|
216
|
-
### 5. Mixed client + server features still work
|
|
217
|
-
|
|
218
|
-
Column visibility, ordering, pinning, and row selection are client state — they don't depend
|
|
219
|
-
on the row model and continue to function with `manualPagination`/`manualSorting`/`manualFiltering`.
|
|
220
|
-
You can have a server-paginated table where the user pins or hides columns locally.
|
|
221
|
-
|
|
222
|
-
## Common Mistakes
|
|
223
|
-
|
|
224
|
-
### Forgetting `manualPagination` / `manualSorting` / `manualFiltering` (CRITICAL)
|
|
225
|
-
|
|
226
|
-
The table double-processes server-processed rows. If the server returned page 2 of 50,
|
|
227
|
-
the table will paginate that 10-row slice again and show "Page 1 of 1".
|
|
228
|
-
|
|
229
|
-
```ts
|
|
230
|
-
// ❌
|
|
231
|
-
useTable({
|
|
232
|
-
features,
|
|
233
|
-
rowModels: {},
|
|
234
|
-
columns,
|
|
235
|
-
data: serverPage.rows,
|
|
236
|
-
rowCount,
|
|
237
|
-
atoms: { pagination: paginationAtom },
|
|
238
|
-
// missing: manualPagination: true
|
|
239
|
-
})
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Leaving `paginatedRowModel` registered when server paginates (CRITICAL)
|
|
243
|
-
|
|
244
|
-
```ts
|
|
245
|
-
// ❌ Factory ships for nothing AND the table re-paginates server-sliced data.
|
|
246
|
-
rowModels: {
|
|
247
|
-
paginatedRowModel: createPaginatedRowModel()
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// ✅
|
|
251
|
-
rowModels: {
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
Same applies to `sortedRowModel`, `filteredRowModel`, `groupedRowModel`, `expandedRowModel`
|
|
256
|
-
when the server owns the slice.
|
|
257
|
-
|
|
258
|
-
### Omitting `rowCount` (CRITICAL)
|
|
259
|
-
|
|
260
|
-
`getPageCount()` returns `1` if the server already paginated. The pager UI locks at
|
|
261
|
-
"Page 1 of 1" and users can't navigate.
|
|
262
|
-
|
|
263
|
-
### Passing `state.pagination` without `onPaginationChange` (CRITICAL)
|
|
264
|
-
|
|
265
|
-
```ts
|
|
266
|
-
// ❌ table.setPageIndex(2) is a no-op — no writeback handler.
|
|
267
|
-
const pagination = ref({ pageIndex: 0, pageSize: 10 })
|
|
268
|
-
useTable({
|
|
269
|
-
features,
|
|
270
|
-
rowModels: {},
|
|
271
|
-
columns,
|
|
272
|
-
data,
|
|
273
|
-
rowCount,
|
|
274
|
-
state: {
|
|
275
|
-
get pagination() {
|
|
276
|
-
return pagination.value
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
manualPagination: true,
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
// ✅ Either pair `state` with `on[State]Change`, OR use `atoms`.
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Mixing `state.pagination` AND `atoms.pagination` for the same slice (HIGH)
|
|
286
|
-
|
|
287
|
-
```ts
|
|
288
|
-
useTable({
|
|
289
|
-
// ...
|
|
290
|
-
state: {
|
|
291
|
-
get pagination() {
|
|
292
|
-
return localPagination.value
|
|
293
|
-
},
|
|
294
|
-
}, // silently ignored
|
|
295
|
-
onPaginationChange: setLocalPagination, // silently ignored
|
|
296
|
-
atoms: { pagination: paginationAtom }, // wins
|
|
297
|
-
})
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
Atoms beat `state`; the `state` plumbing is dead but lingering in the code. Pick one mechanism.
|
|
301
|
-
|
|
302
|
-
### Forgetting to include controlled state in `queryKey` (CRITICAL)
|
|
303
|
-
|
|
304
|
-
```ts
|
|
305
|
-
// ❌ Never refetches when pagination changes.
|
|
306
|
-
useQuery(() => ({
|
|
307
|
-
queryKey: ['people'],
|
|
308
|
-
queryFn: () => fetchPeople(pagination.value),
|
|
309
|
-
}))
|
|
310
|
-
|
|
311
|
-
// ✅
|
|
312
|
-
useQuery(() => ({
|
|
313
|
-
queryKey: ['people', pagination.value],
|
|
314
|
-
queryFn: () => fetchPeople(pagination.value),
|
|
315
|
-
}))
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### Skipping `placeholderData: keepPreviousData` (HIGH)
|
|
319
|
-
|
|
320
|
-
Between fetches the table collapses to 0 rows, the row container collapses, and scroll
|
|
321
|
-
position jumps. `keepPreviousData` keeps the previous page visible during the refetch.
|
|
322
|
-
|
|
323
|
-
### Passing a raw `ref` to `state.pagination` without a getter (CRITICAL — Vue-specific)
|
|
324
|
-
|
|
325
|
-
```ts
|
|
326
|
-
// ❌ Vue can't track .value changes on the captured ref object.
|
|
327
|
-
state: { pagination: pagination }
|
|
328
|
-
|
|
329
|
-
// ✅
|
|
330
|
-
state: { get pagination() { return pagination.value } }
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Hand-rolling sort/page state instead of using the API (CRITICAL — #1 AI tell)
|
|
334
|
-
|
|
335
|
-
```ts
|
|
336
|
-
// ❌ Manual state machine.
|
|
337
|
-
const pageIndex = ref(0)
|
|
338
|
-
const next = () => {
|
|
339
|
-
pageIndex.value++
|
|
340
|
-
refetch()
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// ✅ Built-ins.
|
|
344
|
-
table.nextPage()
|
|
345
|
-
table.setPageIndex(0)
|
|
346
|
-
table.setSorting([{ id: 'age', desc: true }])
|
|
347
|
-
table.setColumnFilters(/* ... */)
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### "API missing" because the feature isn't in `features` (CRITICAL — v9-specific)
|
|
351
|
-
|
|
352
|
-
Server-side pagination still needs `rowPaginationFeature` in `tableFeatures({...})` — that's
|
|
353
|
-
what surfaces `table.setPageIndex`, `table.nextPage`, `table.getPageCount`. The factory in
|
|
354
|
-
`rowModels` is what you drop; the feature stays.
|
|
355
|
-
|
|
356
|
-
```ts
|
|
357
|
-
const features = tableFeatures({ rowPaginationFeature }) // ✅ even with manualPagination
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
## See Also
|
|
361
|
-
|
|
362
|
-
- `tanstack-table/vue/compose-with-tanstack-query` — the Query-specific wiring
|
|
363
|
-
- `tanstack-table/vue/compose-with-tanstack-store` — external atoms in depth
|
|
364
|
-
- `tanstack-table/vue/table-state` — getter rule, atom precedence
|
|
365
|
-
- `tanstack-table/table-core/pagination` — `manualPagination` / `rowCount` semantics
|