table-state
它能做什么
这项技能解释表格状态,例如当前页,在基于信号的 Angular 应用中如何工作。适合需要表格和自己的组件对同一组值作出响应的开发者。
适用场景
- ✓当模板必须显示当前页码或其他表格设置的时候。
- ✓当你需要把表格的页码设置连接到一个 Angular 信号的时候。
- ✓当表格变化后,计算值或副作用没有更新的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/angular-table/skills/table-state/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“如何在按钮的标签中显示我的 Angular 表格的当前页码?”
每周 5 个新技能,1 分钟读完。
工作原理
它展示如何把表格状态保存在信号中,将其传给表格,并通过回调进行更新,使两边保持同步。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Load intent load @tanstack/table-core#table-state first for shared ownership, initialization, updater, and reset rules.
Angular-backed atom reads participate in tracking inside templates, computed, and effect. A value captured outside those contexts is only a snapshot. Use computed for derivation or equality control; wrapping an atom is not required to make it reactive.
Controlled signal setup
<!-- skill-snippet:check tsconfig=scripts/skill-snippets-angular.tsconfig.json -->import { Component, signal } from '@angular/core'
import {
injectTable,
rowPaginationFeature,
tableFeatures,
} from '@tanstack/angular-table'
const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = [{ name: 'Ada' }]
@Component({
selector: 'page-status',
template: `<button (click)="table.nextPage()">
Page {{ table.atoms.pagination.get().pageIndex + 1 }}
</button>`,
})
export class PageStatus {
readonly pagination = signal({ pageIndex: 0, pageSize: 20 })
readonly table = injectTable(() => ({
features,
columns,
data,
state: { pagination: this.pagination() },
onPaginationChange: (next) =>
typeof next === 'function'
? this.pagination.update(next)
: this.pagination.set(next),
}))
}
Reactive boundaries
- Construct in Angular injection context. Signal writes used by the initializer rerun it and call
setOptions; hoist features and columns and keep data references stable. - Supply both
state.paginationandonPaginationChangewhen a signal owns the slice. Resolve updater functions with.update(next)instead of storing the function with.set(next). - For shared state, create a stable atom with
@tanstack/angular-storeand pass it throughatoms. Its writes do not need to flow through a controlled signal in the initializer. - Use
table.store.get()for the flat state. Prefertable.atoms.<slice>.get()for narrow tracked reads.
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/angular-table/dist/types/ for the bundled public declarations. Inspect feature APIs under node_modules/@tanstack/table-core/dist/features/.
常见问题
我总是需要特殊的辅助函数才能让表格的值具有响应性吗?
不需要,这项技能说明,要使一个值具有响应性,不必用辅助函数包装它。
为什么我复制的值没有更新?
在模板、计算值或副作用之外读取的值只是一个快照,不会自行刷新。
表格应该在哪里创建?
表格使用 injectTable 创建,它必须在 Angular 注入上下文中运行。
详情
作者的原始描述
Read and control Table v9 state in angular. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9810
- 许可证
- MIT
- 更新时间
- 2026/10/21
评论
- …
同一仓库的更多技能
getting-started
29k教你的智能体如何在 Alpine.js 中使用 TanStack Table 构建并显示数据表格,涵盖设置、响应式数据和渲染行。
table-state
29k教你的智能体如何在 Alpine.js 中读取和控制表格状态,例如当前页码,使状态变化时屏幕能够更新。
devtools
29k教你的智能体如何把 Angular 表格注册到 TanStack Devtools 面板中,使开发者在构建应用时能检查每个表格。
getting-started
29k教你的智能体如何在 Angular 中创建并显示 TanStack 表格,涵盖 injectTable 设置、模板渲染和行数据的更新。