|
1 | 1 | <script lang="ts">
|
2 |
| - import { writable } from 'svelte/store' |
| 2 | + import type { ColumnDef } from '@tanstack/svelte-table' |
3 | 3 | import {
|
4 | 4 | createSvelteTable,
|
5 |
| - flexRender, |
| 5 | + FlexRender, |
6 | 6 | getCoreRowModel,
|
7 | 7 | } from '@tanstack/svelte-table'
|
8 |
| - import type { ColumnDef, TableOptions } from '@tanstack/svelte-table' |
9 | 8 | import './index.css'
|
10 | 9 |
|
11 | 10 | type Person = {
|
|
96 | 95 | },
|
97 | 96 | ]
|
98 | 97 |
|
99 |
| - const options = writable<TableOptions<Person>>({ |
| 98 | + const options = { |
100 | 99 | data: defaultData,
|
101 | 100 | columns: defaultColumns,
|
102 | 101 | getCoreRowModel: getCoreRowModel(),
|
103 |
| - }) |
104 |
| -
|
105 |
| - const rerender = () => { |
106 |
| - options.update(options => ({ |
107 |
| - ...options, |
108 |
| - data: defaultData, |
109 |
| - })) |
110 | 102 | }
|
111 | 103 |
|
112 | 104 | const table = createSvelteTable(options)
|
|
115 | 107 | <div class="p-2">
|
116 | 108 | <table>
|
117 | 109 | <thead>
|
118 |
| - {#each $table.getHeaderGroups() as headerGroup} |
| 110 | + {#each table.getHeaderGroups() as headerGroup} |
119 | 111 | <tr>
|
120 | 112 | {#each headerGroup.headers as header}
|
121 | 113 | <th colSpan={header.colSpan}>
|
122 | 114 | {#if !header.isPlaceholder}
|
123 |
| - <svelte:component |
124 |
| - this={flexRender( |
125 |
| - header.column.columnDef.header, |
126 |
| - header.getContext() |
127 |
| - )} |
| 115 | + <FlexRender |
| 116 | + content={header.column.columnDef.header} |
| 117 | + context={header.getContext()} |
128 | 118 | />
|
129 | 119 | {/if}
|
130 | 120 | </th>
|
|
133 | 123 | {/each}
|
134 | 124 | </thead>
|
135 | 125 | <tbody>
|
136 |
| - {#each $table.getRowModel().rows as row} |
| 126 | + {#each table.getRowModel().rows as row} |
137 | 127 | <tr>
|
138 | 128 | {#each row.getVisibleCells() as cell}
|
139 | 129 | <td>
|
140 |
| - <svelte:component |
141 |
| - this={flexRender(cell.column.columnDef.cell, cell.getContext())} |
| 130 | + <FlexRender |
| 131 | + content={cell.column.columnDef.cell} |
| 132 | + context={cell.getContext()} |
142 | 133 | />
|
143 | 134 | </td>
|
144 | 135 | {/each}
|
145 | 136 | </tr>
|
146 | 137 | {/each}
|
147 | 138 | </tbody>
|
148 | 139 | <tfoot>
|
149 |
| - {#each $table.getFooterGroups() as footerGroup} |
| 140 | + {#each table.getFooterGroups() as footerGroup} |
150 | 141 | <tr>
|
151 | 142 | {#each footerGroup.headers as header}
|
152 | 143 | <th colSpan={header.colSpan}>
|
153 | 144 | {#if !header.isPlaceholder}
|
154 |
| - <svelte:component |
155 |
| - this={flexRender( |
156 |
| - header.column.columnDef.footer, |
157 |
| - header.getContext() |
158 |
| - )} |
| 145 | + <FlexRender |
| 146 | + content={header.column.columnDef.footer} |
| 147 | + context={header.getContext()} |
159 | 148 | />
|
160 | 149 | {/if}
|
161 | 150 | </th>
|
|
165 | 154 | </tfoot>
|
166 | 155 | </table>
|
167 | 156 | <div class="h-4" />
|
168 |
| - <button on:click={() => rerender()} class="border p-2"> Rerender </button> |
169 | 157 | </div>
|
0 commit comments