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

getting-started

它能做什么

这项技能展示如何在 Ember 应用中用 TanStack Table 构建数据表格。适合希望用该库制作表格布局的 Ember 开发者。

适用场景

  • ✓当你在构建一个需要记录表格的 Ember 页面的时候。
  • ✓当你想用 Ember 的模板标签组件风格来做表格的时候。
  • ✓当你的表格数据存储在 tracked 属性中,并需要在屏幕上更新的时候。

技能链接

https://github.com/TanStack/table/blob/main/packages/ember-table/skills/getting-started/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我需要在 Ember 应用中做一个列出用户的表格。应该如何设置 TanStack Table?”

每周 5 个新技能,1 分钟读完。

工作原理

它提供一个示例组件,定义列、创建表格,并在模板中循环遍历行和单元格。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Load intent load @tanstack/table-core#core first for the headless model, stable inputs, and column inference.

Ember 5.8 or newer requires Embroider or ember-auto-import v2. Prefer .gts or .gjs template-tag components with Glint.

Setup

import Component from '@glimmer/component'
import { tracked } from '@glimmer/tracking'
import {
  FlexRenderCell,
  createColumnHelper,
  tableFeatures,
  useTable,
  type Cell,
  type Row,
} from '@tanstack/ember-table'

type Person = { id: string; name: string }

const features = tableFeatures({})
const columnHelper = createColumnHelper<typeof features, Person>()
const columns = columnHelper.columns([
  columnHelper.accessor('name', { header: 'Name' }),
])
const initialData: Person[] = [{ id: '1', name: 'Ada' }]
const getRowId = (row: Person) => row.id

const getAllCells = (
  row: Row<typeof features, Person>,
): Array<Cell<typeof features, Person>> => row.getAllCells()

export default class PeopleTable extends Component {
  @tracked data = initialData

  table = useTable(this, () => ({
    features,
    columns,
    data: this.data,
    getRowId,
  }))

  get rows() {
    return this.table.getRowModel().rows
  }

  <template>
    <table>
      <tbody>
        {{#each this.rows as |row|}}
          <tr>
            {{#each (getAllCells row) as |cell|}}
              <td><FlexRenderCell @cell={{cell}} /></td>
            {{/each}}
          </tr>
        {{/each}}
      </tbody>
    </table>
  </template>
}

Construction and rendering

useTable takes an options thunk. Read tracked data inside it, and keep features, atoms, and columns stable. In a component, pass this as the owner to bind external-atom cleanup to the component lifecycle. The one-argument thunk form remains available for standalone tables.

Read Table APIs in template-consumed getters. Column, row, cell, and header prototype methods require their receiver, so use a getter or module helper such as getAllCells(row) rather than an extracted method. Wrap event calls the same way.

Use FlexRenderCell, FlexRenderHeader, and FlexRenderFooter for the matching object. Rendered components receive @ctx and optional @options through flexRenderComponent(Component, options).

With tableFeatures({}), render row.getAllCells(). Register columnVisibilityFeature before switching to row.getVisibleCells().

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.

API discovery

Inspect node_modules/@tanstack/ember-table/declarations/index.d.ts, use-table.d.ts, signal.d.ts, and FlexRender.d.ts. Core feature APIs are in node_modules/@tanstack/table-core/dist/features/.

常见问题

这需要哪个 Ember 版本?

这项技能说明,Ember 5.8 或更高版本需要 Embroider 或 ember-auto-import v2。

我应该使用 .gts 文件吗?

这项技能建议在 .gts 或 .gjs 文件中使用模板标签组件,并用 Glint 进行类型检查。

表格数据从哪里来?

示例把数据存储在一个 tracked 属性中,因此它的变化会出现在表格里。

详情

作者的原始描述

Create and render Table v9 with the ember adapter. Route reusable createTableHook defaults, and framework setup; use table-state for reactive ownership.

repo: TanStack/table

热度

GitHub 星标
29k
排名
#9811
许可证
MIT
更新时间
2026/10/21

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能