getting-started
它能做什么
这项技能展示如何在 Angular 应用中用 TanStack Table 构建表格,从定义列和数据到显示各行。适合希望自己设计表格布局的 Angular 开发者。
适用场景
- ✓当你在创建一个显示记录列表表格的 Angular 组件的时候。
- ✓当你的 Angular 表格数据来自信号,并且必须在屏幕上刷新的时候。
- ✓当你想为 Angular 表格添加 Query 或 Virtual 功能的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/angular-table/skills/getting-started/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Angular 应用需要一个显示订单列表的表格。应该如何设置?”
每周 5 个新技能,1 分钟读完。
工作原理
它解释如何在组件中调用 injectTable,传入列和数据,然后在模板中使用 FlexRender 指令循环渲染各行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Load intent load @tanstack/table-core#core first for the headless model, stable inputs, and column inference.
Setup
import { Component, signal } from '@angular/core'
import { FlexRender, injectTable, tableFeatures } from '@tanstack/angular-table'
type Person = { name: string; age: number }
const features = tableFeatures({})
const columns = [
{ accessorKey: 'name', header: 'Name' },
{ accessorKey: 'age', header: 'Age' },
]
@Component({
selector: 'app-table',
imports: [FlexRender],
template: `<table>
<tbody>
@for (row of table.getRowModel().rows; track row.id) {
<tr>
@for (cell of row.getAllCells(); track cell.id) {
<td>
<ng-container *flexRenderCell="cell; let value">{{
value
}}</ng-container>
</td>
}
</tr>
}
</tbody>
</table>`,
})
export class TableComponent {
readonly data = signal<Person[]>([{ name: 'Ada', age: 36 }])
readonly table = injectTable(() => ({ features, columns, data: this.data() }))
}
Construction and rendering
Call injectTable in a component, directive, or service field initializer, or another valid Angular injection context. The adapter binds its cleanup to that context.
Signals read in the options initializer rerun it and call setOptions. Keep features, factories, and columns outside the initializer; return stable data references and derive transformed data with computed outside it.
Import FlexRender for *flexRender, *flexRenderCell, *flexRenderHeader, and *flexRenderFooter. Render values can be primitives, TemplateRef, component types, or flexRenderComponent(...). Use flexRenderComponent for Angular component types; ordinary render functions are already supported directly.
Read for the task
- When adding or configuring optional features, load
intent load @tanstack/table-core#table-featuresand read only references for the requested behavior. - For state ownership or reactive reads, read table-state.
- When tables share features, defaults, or reusable UI, read create-table-hook.
- When Query supplies data or server processing, read with-tanstack-query.
- When virtualizing rows or columns, read with-tanstack-virtual.
- When upgrading v8 code, read migrate-v8-to-v9.
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 注入上下文中调用,这样清理工作会自动完成。
如果我的数据是信号,会发生什么?
信号变化时选项会重新运行,因此表格会用新的值更新。
列应该在组件外部定义吗?
这项技能建议把功能和列保留在响应式选项之外,以免每次更新时都重新构建。
详情
作者的原始描述
Create and render Table v9 with the angular adapter. Route reusable createTableHook components, Query and Virtual integration, and framework setup; use table-state for reactive ownership.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9808
- 许可证
- MIT
- 更新时间
- 2026/10/21
评论
- …
同一仓库的更多技能
getting-started
29k教你的智能体如何在 Alpine.js 中使用 TanStack Table 构建并显示数据表格,涵盖设置、响应式数据和渲染行。
table-state
29k教你的智能体如何在 Alpine.js 中读取和控制表格状态,例如当前页码,使状态变化时屏幕能够更新。
devtools
29k教你的智能体如何把 Angular 表格注册到 TanStack Devtools 面板中,使开发者在构建应用时能检查每个表格。
migrate-v8-to-v9
29k帮你的智能体把 Angular 表格从 TanStack Table v8 迁移到 v9,并依据迁移清单检查设置、渲染、状态和钩子。