Possible implementation of a virtual list ? #89
Replies: 4 comments 8 replies
-
Could you try something like this? <script lang="ts">
import VirtualList from 'svelte-tiny-virtual-list';
import {createTable} from 'svelte-headless-table';
const table = createTable();
const columns = table.createColumns(...);
const {rows} = table.createViewModel(columns);
</script>
<table>
<thead>...</thead>
<!-- use the virtual list component as `tbody` -->
<!-- we can PR `asChild` or `as` support for `svelte-tiny-virtual-list` -->
<VirtualList
width="100%"
height={600}
itemCount={$rows.length}
itemSize={50}>
<svelte:fragment slot="item" let:index let:style>
{@const row = $rows[index]}
<Subscribe rowAttrs={row.attrs()}>
<tr {style} {...rowAttrs}>
{#each row.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<td {...attrs}>
<Render of={cell.render()} />
</td>
</Subscribe>
{/each}
</tr>
</Subscribe>
</svelte:fragment>
</VirtualList>
</table> |
Beta Was this translation helpful? Give feedback.
-
Not really, since the package adds two DOM elements to manage it's list, thus breaking the header columns (not aligned) |
Beta Was this translation helpful? Give feedback.
-
@FluffyDiscord Full disclaimer, I've never used <script lang="ts">
import VirtualList from 'svelte-tiny-virtual-list';
import {createTable} from 'svelte-headless-table';
const table = createTable();
const columns = table.createColumns(...);
const {rows} = table.createViewModel(columns);
</script>
<!-- use the virtual list component as `table` -->
<!-- we can PR `asChild` or `as` support for `svelte-tiny-virtual-list` -->
<VirtualList
width="100%"
height={600}
itemCount={$rows.length}
itemSize={50}>
<thead slot="header">...</thead>
<svelte:fragment slot="item" let:index let:style>
{@const row = $rows[index]}
<Subscribe rowAttrs={row.attrs()}>
<tr {style} {...rowAttrs}>
{#each row.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<td {...attrs}>
<Render of={cell.render()} />
</td>
</Subscribe>
{/each}
</tr>
</Subscribe>
</svelte:fragment>
</VirtualList> |
Beta Was this translation helpful? Give feedback.
-
Update for 2024: I've successfully gotten the Tanstack Virtual Svelte adapter working with Svelte Headless Table using this example and @bryanmylee's proposed solution as guides. The implementation is still basic since I just got it working last night, but it seems to be working just fine with a 10,000 item list. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am aware that we already have pagination plugin in place which works great, but would it be possible to add an "infinite virtual list" pagination plugin ?
The idea would be to limit the table height and specify (or auto-calculate if reasonable) how many items will be shown/rendered and the rendered offset would be managed by scroll, eg. infinite virtual scroll.
Maybe this would be possible to "plug-in" ? https://github.com/Skayo/svelte-tiny-virtual-list
Beta Was this translation helpful? Give feedback.
All reactions