跳到正文
Skillpedia
网站与界面(前端)29k · #9810

table-state

它能做什么

这项技能解释表格状态,例如当前页,在基于信号的 Angular 应用中如何工作。适合需要表格和自己的组件对同一组值作出响应的开发者。

适用场景

  • ✓当模板必须显示当前页码或其他表格设置的时候。
  • ✓当你需要把表格的页码设置连接到一个 Angular 信号的时候。
  • ✓当表格变化后,计算值或副作用没有更新的时候。

技能链接

https://github.com/TanStack/table/blob/main/packages/angular-table/skills/table-state/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/TanStack/table/blob/main/packages/angular-table/skills/table-state/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.pagination and onPaginationChange when 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-store and pass it through atoms. Its writes do not need to flow through a controlled signal in the initializer.
  • Use table.store.get() for the flat state. Prefer table.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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能