custom-features
它能做什么
这项技能展示如何构建可复用的功能,即插件,为 TanStack Table 添加新的状态或行为。适合内置功能无法覆盖其需求的高级开发者。
适用场景
- ✓当你需要添加可复用的状态或行为到表格对象中的时候。
- ✓当内置选项和类型化元数据无法处理你的渲染器或应用设置的时候。
- ✓当你编写的插件必须正确注册生命周期钩子和表格方法的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/table-core/skills/custom-features/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“TanStack Table 的内置功能无法满足我的需求。我该如何编写自己的插件?”
每周 5 个新技能,1 分钟读完。
工作原理
它会逐步讲解:声明该功能、保留用户状态、在生命周期钩子中添加表格和对象方法,并用稳定的功能对象注册插件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Author a custom feature
Read core and feature architecture first. Use a plugin for reusable state or behavior that must augment Table objects. Built-in options and typed tableMeta/columnMeta are usually enough for renderer callbacks and application configuration.
Implementation workflow
- Identify the state, options, and object methods the behavior owns. If it only passes callbacks or renderer data, read scoped meta typing and use meta instead.
- Before declaring plugin types or writing lifecycle hooks, read the complete plugin example. It enumerates all 10 public FeatureMaps, the API assignment helpers, lifecycle ordering, and the advanced row-model maps.
- Declare the feature key in
Plugins. Merge only FeatureMaps with matching runtime implementations; declarations alone install no behavior. - Preserve user state after defaults in
getInitialState; connect state updaters in default options. Install table methods withassignTableAPIsand object methods withassignPrototypeAPIsinside the corresponding lifecycle hooks. - Keep the feature object and
tableFeatures({ customFeature })result stable. Register the plugin throughtableFeaturesso inference and composition include it. - Verify the advertised state, options, methods, and resets on a constructed table. Each declared API must exist at runtime; reset behavior must respect the state owner.
Lifecycle boundaries
Use initTableInstanceData for mutable data owned by one table and resetTableInstanceData for clearing its transient contents. All feature initialization finishes before any constructTableAPIs hook. Keep method installation separate from data allocation.
Prototype methods are shared across the table's rows, columns, cells, or headers. Read per-object values through the method's current instance, and use the supported instance-data hooks for mutable fields. Read the example's installation rules before adding memoized methods or advanced row-model/cache wiring.
Common failures
- Types without matching runtime hooks advertise APIs that do not exist.
- Ad hoc mutation of constructed instances bypasses feature registration and inferred composition.
- Treating the density example as the only extension pattern misses column definitions and the other public FeatureMaps. Choose the maps required by the behavior; advanced row-model declarations also require runtime pipeline/cache wiring.
Installed API discovery
Inspect node_modules/@tanstack/table-core/dist/types/TableFeatures.d.ts, the exported *_FeatureMap interfaces in dist/types/, and assignTableAPIs/assignPrototypeAPIs in dist/utils.d.ts. Follow declarations under dist/features/ for comparable stock lifecycle signatures.
常见问题
什么时候不应该编写自定义功能?
这项技能说明,如果某个行为只是传递回调或渲染器数据,你应改用类型化元数据。
声明功能类型会安装它的行为吗?
不会,这项技能说明仅有声明不会安装任何东西,运行时的实现必须与声明的类型一致。
插件应该在哪里注册?
通过 tableFeatures 调用注册,这样类型推断和组合才会包含它。
详情
作者的原始描述
Implement a Table v9 plugin when built-ins and typed meta are insufficient. Covers FeatureMaps, runtime lifecycle hooks, prototypes, and a complete checked example.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9835
- 许可证
- MIT
- 更新时间
- 2026/10/21
评论
- …
同一仓库的更多技能
getting-started
29k教你的智能体如何在 Alpine.js 中使用 TanStack Table 构建并显示数据表格,涵盖设置、响应式数据和渲染行。
table-state
29k教你的智能体如何在 Alpine.js 中读取和控制表格状态,例如当前页码,使状态变化时屏幕能够更新。
devtools
29k教你的智能体如何把 Angular 表格注册到 TanStack Devtools 面板中,使开发者在构建应用时能检查每个表格。
getting-started
29k教你的智能体如何在 Angular 中创建并显示 TanStack 表格,涵盖 injectTable 设置、模板渲染和行数据的更新。