table-state
它能做什么
这项技能解释如何跟踪表格的设置,例如当前显示的是哪一页,以及如何在 Alpine.js 页面中更新它们。适合需要表格与页面其他部分保持同步的开发者。
适用场景
- ✓当表格的当前页或其他设置需要显示在按钮或标签中的时候。
- ✓当你想从自己的代码中控制表格状态的一部分的时候。
- ✓当状态变化后表格没有在屏幕上更新的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/alpine-table/skills/table-state/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Alpine.js 表格在点击下一页后,页码没有更新。我该如何解决?”
每周 5 个新技能,1 分钟读完。
工作原理
它展示如何通过 getter 和回调传递受控状态,使 Alpine 能读取最新的值,并在其变化时更新屏幕。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Load intent load @tanstack/table-core#table-state first for shared ownership, initialization, updater, and reset rules.
Alpine's table proxy makes reads inside x-text, x-for, x-if, bound attributes, x-effect, and Alpine getters reactive. Event handlers read the current value when invoked. A captured value outside a binding does not become a continuing subscription, and there is no table.Subscribe component.
Controlled getter setup
<!-- skill-snippet:check -->import Alpine from 'alpinejs'
import {
createTable,
rowPaginationFeature,
tableFeatures,
type PaginationState,
} from '@tanstack/alpine-table'
const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = [{ name: 'Ada' }]
Alpine.data('pagedTable', () => {
const local = Alpine.reactive<{ pagination: PaginationState }>({
pagination: { pageIndex: 0, pageSize: 10 },
})
const table = createTable({
features,
columns,
data,
state: {
get pagination() {
return local.pagination
},
},
onPaginationChange: (next) => {
local.pagination =
typeof next === 'function' ? next(local.pagination) : next
},
})
return { table }
})
Read table.atoms.pagination.get().pageIndex directly in an Alpine binding.
Reactive boundaries
- A controlled slice needs a getter and callback.
state: { pagination: local.pagination }captures the old object when the owner later replaces it. - Expose changing data through
get data()and keep features, columns, and derived data stable outside reevaluated getters. - The proxy normally reevaluates all Table-reading bindings for every state change. A narrow atom read does not by itself narrow that broad invalidation.
- For shared state, pass a stable external atom through
atoms; omit controlled state and its callback for the same slice.
Read for the task
For advanced reactive boundaries, shared atoms, or detailed subscription examples, read reactivity. For construction or rendering setup, read getting-started.
API discovery
Inspect node_modules/@tanstack/alpine-table/dist/index.d.ts, createTable.d.ts, and reactivity.d.ts. Core feature APIs are in node_modules/@tanstack/table-core/dist/features/.
常见问题
为什么表格状态变化时不刷新?
通常是因为数据或状态只被复制了一次,而不是通过 getter 读取,因此 Alpine 无法看到之后的变化。
我可以在点击处理函数中一次性读取一个值吗?
可以,事件处理函数在运行的那一刻会读取当前的值。
这会取代核心表格指南吗?
不会,它在核心指南中共享的所有权和重置规则之上,增加了 Alpine 特有的规则。
详情
作者的原始描述
Read and control Table v9 state in alpine. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9806
- 许可证
- MIT
- 更新时间
- 2026/10/21
评论
- …
同一仓库的更多技能
getting-started
29k教你的智能体如何在 Alpine.js 中使用 TanStack Table 构建并显示数据表格,涵盖设置、响应式数据和渲染行。
devtools
29k教你的智能体如何把 Angular 表格注册到 TanStack Devtools 面板中,使开发者在构建应用时能检查每个表格。
getting-started
29k教你的智能体如何在 Angular 中创建并显示 TanStack 表格,涵盖 injectTable 设置、模板渲染和行数据的更新。
migrate-v8-to-v9
29k帮你的智能体把 Angular 表格从 TanStack Table v8 迁移到 v9,并依据迁移清单检查设置、渲染、状态和钩子。