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

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 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-features and 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能