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

getting-started

它能做什么

这项技能展示如何在使用 Alpine.js 构建的网页中,借助 TanStack Table 库创建并显示数据表格。适合希望自己设计表格样式的无头表格网页开发者。

适用场景

  • ✓当你在构建一个需要结构化记录表格的 Alpine.js 页面的时候。
  • ✓当你的表格数据随时间变化,表格必须在屏幕上同步更新的时候。
  • ✓当你想用 FlexRender 辅助函数渲染表头和单元格的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我正在做一个 Alpine.js 页面,用表格列出客户。应该如何用 TanStack Table 设置它?”

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

工作原理

它提供根据列定义和数据创建表格的代码模式,然后展示如何用 Alpine 的模板循环在页面中渲染表头和行。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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

Setup

import Alpine from 'alpinejs'
import {
  FlexRender,
  createTable,
  tableFeatures,
  type ColumnDef,
} from '@tanstack/alpine-table'

type Person = { id: string; name: string }
const features = tableFeatures({})
const columns: Array<ColumnDef<typeof features, Person>> = [
  { accessorKey: 'name', header: 'Name' },
]

Alpine.data('peopleTable', () => {
  const local = Alpine.reactive({
    data: [{ id: '1', name: 'Ada' }] as Array<Person>,
  })
  const table = createTable({
    features,
    columns,
    get data() {
      return local.data
    },
    getRowId: (row) => row.id,
  })

  return { table, FlexRender }
})

window.Alpine = Alpine
Alpine.start()

Render real table structure with x-for; use x-html="FlexRender({ header })" or x-html="FlexRender({ cell })" only for renderer output.

Construction and rendering

Wrap changing data in Alpine.reactive and expose it with get data(). The adapter tracks option getters; data: local.data captures a snapshot and does not follow later array replacements. Keep static columns and features outside getters.

The returned table is a reactive proxy. Read Table APIs directly in x-text, x-for, x-if, or bound attributes; no Subscribe component is needed.

Build table structure and interactive controls as real Alpine markup. Use x-html="FlexRender({ header })" or x-html="FlexRender({ cell })" for renderer output. Alpine does not initialize directives inside x-html strings; use templates or Alpine.bind bundles for buttons and inputs.

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/alpine-table/dist/index.d.ts, createTable.d.ts, and reactivity.d.ts. Core feature APIs are in node_modules/@tanstack/table-core/dist/features/.

常见问题

我需要先熟悉 TanStack Table 吗?

不需要深入了解。这项技能指向核心指南获取背景知识,然后讲解 Alpine 特有的设置。

如何让表格与变化的数据保持同步?

这项技能建议把数据包装在 Alpine 的响应式 store 中,并通过 getter 暴露出来。

它只适用于 Alpine.js 吗?

是的,它涵盖 Table v9 的 Alpine 版本,其他框架有各自的指南。

详情

作者的原始描述

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

repo: TanStack/table

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能