## Demo: tanstack-table ### TanStackTable.svelte ```svelte

TanStack Table needs no special setup — it's a headless, framework-agnostic table library with a Svelte 5 runes adapter. You install it and import from @tanstack/svelte-table; in Mochi it bundles straight into whichever island imports it.

Declare which features you need with tableFeatures, pass your columns and data, then render the header/cell definitions with <FlexRender />:

Full API at tanstack.com/table.

Read-only table — server-rendered, zero JS

The whole table is plain server HTML: no mochi:hydrate, so nothing ships to the browser. This only makes sense when you don't need sorting, filtering, or any client interaction — otherwise reach for an island.

Sortable table — mochi:hydrate

Registering rowSortingFeature makes the headers clickable — cycle ascending → descending → unsorted. Sorting runs on the client, so this card is a hydrated island.

``` ### BasicTable.svelte ```svelte
{#each table.getHeaderGroups() as headerGroup (headerGroup.id)} {#each headerGroup.headers as header (header.id)} {/each} {/each} {#each table.getRowModel().rows as row (row.id)} {#each row.getAllCells() as cell (cell.id)} {/each} {/each}
{#if !header.isPlaceholder} {/if}
``` ### SortableTable.svelte ```svelte
{#each table.getHeaderGroups() as headerGroup (headerGroup.id)} {#each headerGroup.headers as header (header.id)} {/each} {/each} {#each table.getRowModel().rows as row (row.id)} {#each row.getAllCells() as cell (cell.id)} {/each} {/each}
{#if !header.isPlaceholder} {/if}
``` ### data.ts ```ts export type Person = { firstName: string; lastName: string; age: number }; export const people: Person[] = [ { firstName: 'tanner', lastName: 'linsley', age: 24 }, { firstName: 'tandy', lastName: 'miller', age: 40 }, { firstName: 'joe', lastName: 'dirte', age: 45 }, { firstName: 'kevin', lastName: 'vandy', age: 33 }, { firstName: 'nora', lastName: 'reed', age: 29 }, ]; ``` ### routes.ts ```ts import { Mochi } from 'mochi-framework'; import type { MochiRouteValue } from 'mochi-framework'; export const routes: Record = { '/demos/tanstack-table': Mochi.page('./src/demos/tanstack-table/TanStackTable.svelte'), }; ``` ### index.ts ```ts import { Mochi, logger } from 'mochi-framework'; import { routes } from './routes'; await Mochi.serve({ port: 3333, development: process.env.MODE === 'development', routes, }); logger.info('Server running at http://localhost:3333'); ```