The @tanstack/lit-table 适配器是围绕核心表格逻辑的包装器。它的主要工作是管理 "lit" 方式的状态,提供类型以及单元格/表头/表尾模板的渲染实现。
@tanstack/lit-table 重新导出 @tanstack/table-core 的所有 API 以及以下内容
是一个响应式控制器,提供一个 table API,它接受一个 options 对象并返回一个表格实例。
import { TableController } from '@tanstack/lit-table'
@customElement('my-table-element')
class MyTableElement extends LitElement {
private tableController = new TableController<Person>(this)
protected render() {
const table = this.tableController.table(options)
// ...render your table
}
}
import { TableController } from '@tanstack/lit-table'
@customElement('my-table-element')
class MyTableElement extends LitElement {
private tableController = new TableController<Person>(this)
protected render() {
const table = this.tableController.table(options)
// ...render your table
}
}
一个用于渲染带有动态值的单元格/表头/表尾模板的实用函数。
示例
import { flexRender } from '@tanstack/lit-table'
//...
return html`
<tbody>
${table
.getRowModel()
.rows.slice(0, 10)
.map(
row => html`
<tr>
${row
.getVisibleCells()
.map(
cell => html`
<td>
${flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</td>
`
)}
</tr>
`
)}
</tbody>
`
import { flexRender } from '@tanstack/lit-table'
//...
return html`
<tbody>
${table
.getRowModel()
.rows.slice(0, 10)
.map(
row => html`
<tr>
${row
.getVisibleCells()
.map(
cell => html`
<td>
${flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</td>
`
)}
</tr>
`
)}
</tbody>
`
您的每周 JavaScript 新闻。每周一免费发送给超过 10 万名开发者。