`@tanstack/lit-table` 适配器是核心表格逻辑的包装器。它的主要工作是 "lit" 方式管理状态,提供类型以及单元格/表头/表尾模板的渲染实现。
`@tanstack/lit-table` 重新导出 ` @tanstack/table-core` 的所有 API 以及以下内容:
是一个响应式控制器,提供一个 `table` API,该 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 万开发者。