material-svelte-tanstack-table
v0.6.0
Published
A fully featured Svelte Material UI (SMUI) implementation of TanStack Table V9 for Svelte 5, written from the ground up in TypeScript.
Maintainers
Readme
material-svelte-tanstack-table
A fully featured Svelte Material UI data table for Svelte 5, built on TanStack Table v9. A port of Material React Table with a runes and snippets API.
Install
npm install material-svelte-tanstack-tableNeeds Svelte 5. Import the stylesheet once (SMUI only publishes Sass, so the package ships its styles pre-compiled):
import 'material-svelte-tanstack-table/styles.css';Theme the table with the Material --mdc-theme-* CSS variables.
Usage
<script lang="ts">
import { MaterialSvelteTable, type MRT_ColumnDef } from 'material-svelte-tanstack-table';
type Person = { name: string; age: number };
// define columns once, outside of any reactive code
const columns: MRT_ColumnDef<Person>[] = [
{ accessorKey: 'name', header: 'Name' },
{ accessorKey: 'age', header: 'Age' },
];
let data = $state<Person[]>([
{ name: 'John', age: 30 },
{ name: 'Sara', age: 25 },
]);
</script>
<MaterialSvelteTable
options={{
columns,
// options that change over time are passed as getters
get data() {
return data;
},
enableRowSelection: true,
}}
/>Icons
Every icon the table renders can be replaced with the icons option. Pass only the ones you want to change; the rest
keep their defaults. An icon is a Svelte component that takes optional class and style props.
<script lang="ts">
import { MaterialSvelteTable, MRT_Default_Icons } from 'material-svelte-tanstack-table';
import MyFilterIcon from './MyFilterIcon.svelte';
</script>
<MaterialSvelteTable options={{ columns, data, icons: { FilterAltIcon: MyFilterIcon } }} />MRT_Default_Icons also exports the built-in icons, so you can use them in your own snippets next to custom markup, for
example in a Header, Cell, Footer, rowActions or topToolbarCustomActions snippet:
{#snippet nameHeader()}
<span><MRT_Default_Icons.EditIcon /> <strong>First Name</strong></span>
{/snippet}See the Features / Icons With Custom HTML stories in Storybook for headers, cells, footers, row actions and toolbar examples.
Dependencies
Matching text in cells is highlighted by a small built-in helper. The table doesn't depend on highlight-words or any
other highlighting package.
Docs
The documentation site is in apps/material-tanstack-table-docs,
live at material-tanstack-svelte-table.pages.dev, with a
Storybook alongside it.
This package is one of four table libraries in the
svelte-tables repository.
License
MIT
