Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"baseBranch": "main",
"updateInternalDependencies": "patch",
"fixed": [],
"linked": [["@tanstack/*"]],
"linked": [["@tanstack/*", "!@tanstack/solid-table"]],
"ignore": [],
"privatePackages": { "version": false, "tag": false },
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
Expand Down
10 changes: 10 additions & 0 deletions .changeset/solid-table-solid-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@tanstack/solid-table': major
---

Move `@tanstack/solid-table` to Solid 2. The adapter now requires `solid-js` and `@solidjs/web` 2.0. Solid 1 apps stay on v9.

- Table state atoms are Solid 2 signals and memos, so reads track in JSX, memos and effects as before. Writes are applied when Solid flushes, like any Solid 2 write. Table APIs use updater functions, so several updates in one tick compose.
- `FlexRender` calls cell, header and footer templates where they render, so their reads are tracked and a template updates when what it reads changes. Templates are typed as Solid 2's `Element`.
- A Solid store array passed as `data` (for example Solid Query v6 data, which updates in place) updates the table when its items change.
- `createTableHook` contexts use Solid 2 providers. `useHeaderContext()` returns a view of the header that carries the pre-bound header components, so a header and its footer no longer overwrite each other's components.
7 changes: 7 additions & 0 deletions .changeset/table-core-merge-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/table-core': patch
---

`table.setOptions(updater)` now applies the updater to the latest options inside the options store update, so back-to-back calls in one tick compose with adapters that batch writes. `constructTable` also merges the initial options through `mergeOptions` when one is provided, so adapter getters such as `get data()` stay live.

Event handler getters such as `column.getToggleSortingHandler()`, `row.getToggleSelectedHandler()`, `row.getToggleExpandedHandler()`, `column.getToggleGroupingHandler()`, `header.getResizeHandler()` and the cell selection handlers now check whether the action is allowed when the handler runs, not when it is created. A handler created before an `enable*` option changes no longer acts on the old value, and creating a handler no longer reads table state, so Solid doesn't warn about an untracked read.
4 changes: 3 additions & 1 deletion docs/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ npm install @tanstack/vue-devtools @tanstack/vue-table-devtools
npm install @tanstack/solid-devtools @tanstack/solid-table-devtools
```

The Solid devtools currently support Solid 1, so they work with `@tanstack/solid-table` v9. Solid 2 support (`@tanstack/solid-table` v10) will follow TanStack Devtools.

# Angular

```sh
Expand Down Expand Up @@ -195,7 +197,7 @@ See the [Vue row-selection example](./framework/vue/examples/row-selection).
# Solid

```tsx
import { render } from 'solid-js/web'
import { render } from 'solid-js/web' // Solid 1, with @tanstack/solid-table v9
import { createTable } from '@tanstack/solid-table'
import { TanStackDevtools } from '@tanstack/solid-devtools'
import {
Expand Down
16 changes: 7 additions & 9 deletions docs/framework/solid/guide/cell-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,13 @@ Because a reorder can widen a selection onto columns the user never picked, some

```ts
createEffect(
on(
() => [
table.atoms.columnOrder.get(),
table.atoms.columnPinning.get(),
table.atoms.columnVisibility.get(),
],
() => table.resetCellSelection(true),
{ defer: true }, // skip the first run so an initialState selection survives
),
() => [
table.atoms.columnOrder.get(),
table.atoms.columnPinning.get(),
table.atoms.columnVisibility.get(),
],
() => table.resetCellSelection(true),
{ defer: true }, // skip the first run so an initialState selection survives
)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/framework/solid/guide/cell-spanning.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ A covered cell reports a span of `0`, and the renderer skips it. This is the sam
<For each={row.getVisibleCells()}>
{(cell) => (
// A covered cell reports a span of 0 on at least one axis. Skip it.
// Do not render `rowSpan={0}`: in HTML that means "span to the end of
// Do not render `rowspan={0}`: in HTML that means "span to the end of
// the row group", which merges the cell down the entire tbody.
<Show when={!cell.getIsCovered()}>
<td rowSpan={cell.getRowSpan()} colSpan={cell.getColSpan()}>
<td rowspan={cell.getRowSpan()} colspan={cell.getColSpan()}>
<table.FlexRender cell={cell} />
</td>
</Show>
Expand Down
15 changes: 15 additions & 0 deletions docs/framework/solid/guide/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
title: Migrating to TanStack Table V9 (Solid)
---

## Solid 2

`@tanstack/solid-table` v10 is the Solid 2 adapter. It has the same API as v9. Solid 1 apps stay on v9, and everything else in this guide applies to both.

To move a v9 Solid table to v10:

- Install `solid-js` and `@solidjs/web` 2.0 alongside `@tanstack/solid-table@10`.
- Follow the Solid 2 migration for your own code: `solid-js/web` becomes `@solidjs/web`, `mergeProps`/`splitProps` become `merge`/`omit`, effects take a compute function and an apply function, `<Index>` becomes `<For keyed={false}>`, `classList` becomes `class`, and `colSpan`/`rowSpan` become `colspan`/`rowspan`.
- Type cell and header renderers as `Element` from `solid-js` instead of `JSX.Element`.
- Table state writes are batched like any Solid 2 write. A read straight after a write returns the previous value until Solid flushes. Updates built on the previous value still compose, because table APIs use updater functions. Call `flush()` from `solid-js` if you need the new value right away.
- `FlexRender` calls `cell`, `header` and `footer` templates where they render, so a template's reads are tracked and it updates when they change. In your own components, read table state in JSX, a memo or an accessor, not in the component body: Solid 2 warns in development about a body read, because it won't update.
- A Solid store passed as `data`, such as Solid Query v6 data, updates the table when it changes in place.
- `createTableHook` contexts are their own providers in Solid 2, which the hook handles for you. `useHeaderContext()` returns a view of the header that also carries the pre-bound header components, so compare its prototype, not the object itself, with the original header.
- The Solid devtools (`@tanstack/solid-table-devtools`) do not support Solid 2 yet.

## What's New in TanStack Table V9

TanStack Table V9 delivers major performance improvements, hundreds of bug fixes, new and refreshed features, and optional helpers for composing and managing tables. Despite the scale of the release, the headless model, core table logic, column definitions, and rendering patterns remain familiar. Here are the key changes:
Expand Down
74 changes: 39 additions & 35 deletions docs/framework/solid/guide/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,34 @@ const table = createTable({

TanStack Query can own the request lifecycle while TanStack Table owns the controlled pagination state. See the complete [With TanStack Query example](../examples/with-tanstack-query), which includes both patterns below.

These snippets use `@tanstack/solid-query` v6, the Solid 2 version. Query data is async in Solid 2, so render the table under a `<Loading>` boundary; reads wait there until the first page arrives, and `keepPreviousData` keeps the current page on screen while the next one loads. Read the query inputs in the options function, where they are tracked, rather than inside `queryFn`. Query data is a Solid store that updates in place, which the table handles.

##### Page-Index Pagination with `useQuery`

Include the pagination state in the query key, return the requested rows plus a total `rowCount`, and pass both to the table:

```tsx
const dataQuery = useQuery(() => ({
queryKey: ['people', 'offset', pagination(), sorting(), globalFilter()],
queryFn: () =>
fetchPeople({
pagination: pagination(),
sorting: sorting(),
globalFilter: globalFilter(),
}),
placeholderData: keepPreviousData,
}))
const dataQuery = useQuery(() => {
const variables = {
pagination: pagination(),
sorting: sorting(),
globalFilter: globalFilter(),
}
return {
queryKey: ['people', 'offset', variables],
queryFn: () => fetchPeople(variables),
placeholderData: keepPreviousData,
}
})

const table = createTable({
features,
columns,
get data() {
return dataQuery.data?.rows ?? []
return dataQuery.data.rows
},
get rowCount() {
return dataQuery.data?.rowCount
return dataQuery.data.rowCount
},
state: {
get pagination() {
Expand All @@ -159,35 +163,35 @@ This supports page counts, page-number navigation, and `lastPage()` because the
For a cursor API, return the current rows, a `nextCursor`, and `hasNextPage`. The cursor can be the last row ID when IDs are unique and the server's ordering is stable:

```tsx
const dataQuery = useInfiniteQuery(() => ({
queryKey: [
'people',
'cursor',
pagination().pageSize,
sorting(),
globalFilter(),
],
queryFn: ({ pageParam }) =>
fetchPeople({
cursor: pageParam,
pageSize: pagination().pageSize,
sorting: sorting(),
globalFilter: globalFilter(),
}),
initialPageParam: null,
getNextPageParam: (lastPage) => lastPage.nextCursor,
}))

const currentPage = () => dataQuery.data?.pages[pagination().pageIndex]
const dataQuery = useInfiniteQuery(() => {
const variables = {
pageSize: pagination().pageSize,
sorting: sorting(),
globalFilter: globalFilter(),
}
return {
queryKey: ['people', 'cursor', variables],
queryFn: ({ pageParam }) =>
fetchPeople({ cursor: pageParam, ...variables }),
initialPageParam: null,
getNextPageParam: (lastPage) => lastPage.nextCursor,
}
})

const pageAt = (index: number): PeoplePage | undefined =>
dataQuery.data.pages[index]
const currentPage = () => pageAt(pagination().pageIndex)
const canNextPage = () =>
Boolean(dataQuery.data?.pages[pagination().pageIndex + 1]) ||
Boolean(pageAt(pagination().pageIndex + 1)) ||
Boolean(currentPage()?.hasNextPage)

const emptyRows: Array<Person> = []

const table = createTable({
features,
columns,
get data() {
return currentPage()?.rows ?? []
return currentPage()?.rows ?? emptyRows
},
pageCount: -1,
state: {
Expand All @@ -202,7 +206,7 @@ const table = createTable({
async function goToNextPage() {
const nextPageIndex = pagination().pageIndex + 1

if (!dataQuery.data?.pages[nextPageIndex]) {
if (!pageAt(nextPageIndex)) {
const result = await dataQuery.fetchNextPage()
if (!result.data?.pages[nextPageIndex]) return
}
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/guide/row-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ If you want a simpler row selection UI, you can just hook up click events to the
<For each={table.getRowModel().rows}>
{(row) => (
<tr
classList={{ selected: row.getIsSelected() }}
class={{ selected: row.getIsSelected() }}
onClick={row.getToggleSelectedHandler()}
>
<For each={row.getVisibleCells()}>{(cell) => <td>{/* */}</td>}</For>
Expand Down
12 changes: 11 additions & 1 deletion docs/framework/solid/guide/table-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ table.setPageSize(25)

Use APIs like `table.setSorting(...)`, `table.setColumnFilters(...)`, `column.toggleVisibility()`, or `row.toggleSelected()` instead of manually editing the underlying state object.

State writes follow Solid 2's batching. A write is applied when Solid next flushes, so a read in the same synchronous block still returns the previous value. Updates that build on the previous value compose correctly, because table APIs pass updater functions, and updaters see pending writes:

```tsx
table.nextPage()
table.nextPage() // both apply: the page index moves forward by 2
table.atoms.pagination.get().pageIndex // still the old page until the flush
```

Call `flush()` from `solid-js` if code needs the new value straight away.

If you only care about setting starting values, use `initialState`. If you want to reset a state slice back to its initial value, use that feature's reset API.

If you really do need to write a state slice directly, the low-level write surface for internally owned state is the matching base atom:
Expand Down Expand Up @@ -221,7 +231,7 @@ If you need easy access to table state in other parts of your application, you c

#### External Atoms

Use external atoms when the app should own one or more table state slices as TanStack Store atoms. Create stable writable atoms with `createAtom`, pass them to `atoms`, and subscribe to them with `useSelector` anywhere else in your app. `@tanstack/solid-store` is only needed by your app if you choose this pattern; the Solid table adapter itself uses Solid-native reactivity.
Use external atoms when the app should own one or more table state slices as TanStack Store atoms. Create stable writable atoms with `createAtom`, pass them to `atoms`, and subscribe to them with `useSelector` anywhere else in your app. `@tanstack/solid-store` is only needed by your app if you choose this pattern; the Solid table adapter itself uses Solid-native reactivity. Use a release of `@tanstack/solid-store` that supports Solid 2. Inside your table's own components, `table.atoms.pagination.get()` is already a reactive read of the external atom.

```tsx
import { createAtom, useSelector } from '@tanstack/solid-store'
Expand Down
8 changes: 5 additions & 3 deletions docs/framework/solid/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ TanStack Table is a headless table library. It manages your table's state and lo
## Installation

```bash
npm install @tanstack/solid-table
npm install @tanstack/solid-table solid-js @solidjs/web
```

`@tanstack/solid-table` v10 supports Solid 2. For Solid 1, install `@tanstack/solid-table@9`.

## Your First Table

The component below is complete. Paste it into a Solid app and you will see a working table.
Expand Down Expand Up @@ -113,7 +115,7 @@ A few things to note:
- `tableFeatures({})` declares which optional features the table uses. Registering only what you need keeps bundles small and gives TypeScript accurate types for the table instance.
- The `get data()` getter keeps the table reactive. When the signal updates, the table sees the new data. Passing `data: data()` would capture a one-time snapshot.
- `FlexRender` renders the `header`, `cell`, and `footer` definitions from your columns, whether they are plain values or Solid components. It is also available on the table instance as `table.FlexRender`.
- The `key` option is optional unless you use the [TanStack Table Devtools](../../devtools). The devtools identify tables by `key`, and you register a table by calling `useTanStackTableDevtools(table)` from `@tanstack/solid-table-devtools`.
- The `key` option is optional unless you use the [TanStack Table Devtools](../../devtools). The devtools identify tables by `key`. The Solid devtools adapter does not support Solid 2 yet.

See the full [Basic createTable example](./examples/basic-use-table) for a runnable version with more columns and a footer.

Expand Down Expand Up @@ -192,7 +194,7 @@ Clicking a header now toggles between ascending, descending, and unsorted. Every

## Where to Go Next

**Table state.** In v9, table state is backed by TanStack Store atoms that plug directly into Solid's fine-grained reactivity. You usually do not need to manage it yourself. Set `initialState` for starting values and call feature APIs like `table.setSorting(...)` or `table.nextPage()`. When your app should own a state slice, or you want fine-grained subscriptions, read the [Table State Guide](./guide/table-state.md). It is the foundational guide for everything else.
**Table state.** Table state is backed by TanStack Store atoms that plug directly into Solid's fine-grained reactivity. Like any Solid 2 signal, a state write is applied at the next flush, so a read straight after `table.setSorting(...)` in the same event handler still returns the previous value. You usually do not need to manage it yourself. Set `initialState` for starting values and call feature APIs like `table.setSorting(...)` or `table.nextPage()`. When your app should own a state slice, or you want fine-grained subscriptions, read the [Table State Guide](./guide/table-state.md). It is the foundational guide for everything else.

**Feature guides.** Each feature has its own guide, such as [Column Filtering](./guide/column-filtering.md), [Pagination](./guide/pagination.md), [Row Selection](./guide/row-selection.md), and [Column Visibility](./guide/column-visibility.md).

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The `@tanstack/vue-table` package works with Vue 3.2 or newer.

# Solid

The `@tanstack/solid-table` package works with Solid 1.3 or newer.
The `@tanstack/solid-table` package works with Solid 2 (`solid-js` and `@solidjs/web` 2.0 or newer). For Solid 1, use `@tanstack/solid-table` v9.

# Svelte

Expand Down
7 changes: 4 additions & 3 deletions examples/solid/aggregation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"devDependencies": {
"@faker-js/faker": "^10.6.0",
"@rolldown/binding-wasm32-wasi": "~1.3.2",
"@solidjs/vite-plugin": "^3.0.0",
"typescript": "6.0.3",
"vite": "^8.3.8",
"vite-plugin-solid": "^2.11.16"
"vite": "^8.3.8"
},
"dependencies": {
"@solidjs/web": "^2.0.0",
"@tanstack/solid-table": "^9.3.1",
"solid-js": "^1.9.19"
"solid-js": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion examples/solid/aggregation/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function App() {
<tr>
<For each={group.headers}>
{(header) => (
<th colSpan={header.colSpan}>
<th colspan={header.colSpan}>
{header.isPlaceholder ? null : header.column.id ===
'item' ? (
`${rowSource()} total`
Expand Down
2 changes: 1 addition & 1 deletion examples/solid/aggregation/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @refresh reload */
import { render } from 'solid-js/web'
import { render } from '@solidjs/web'
import './index.css'
import App from './App'

Expand Down
2 changes: 1 addition & 1 deletion examples/solid/aggregation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"jsxImportSource": "@solidjs/web",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/aggregation/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid'
import solid from '@solidjs/vite-plugin'
export default defineConfig({
server: {
port: 7777,
allowedHosts: true,
},
plugins: [solidPlugin()],
plugins: [solid()],
build: { target: 'esnext' },
})
9 changes: 4 additions & 5 deletions examples/solid/basic-app-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
"license": "MIT",
"devDependencies": {
"@rolldown/binding-wasm32-wasi": "~1.3.2",
"@solidjs/vite-plugin": "^3.0.0",
"typescript": "6.0.3",
"vite": "^8.3.8",
"vite-plugin-solid": "^2.11.16"
"vite": "^8.3.8"
},
"dependencies": {
"@faker-js/faker": "^10.6.0",
"@tanstack/solid-devtools": "^0.8.14",
"@solidjs/web": "^2.0.0",
"@tanstack/solid-table": "^9.3.1",
"@tanstack/solid-table-devtools": "^9.3.2",
"solid-js": "^1.9.19"
"solid-js": "^2.0.0"
}
}
5 changes: 1 addition & 4 deletions examples/solid/basic-app-table/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createTableHook } from '@tanstack/solid-table'
import { useTanStackTableDevtools } from '@tanstack/solid-table-devtools'
import { For, createSignal } from 'solid-js'
import { makeData } from './makeData'
import type { Person } from './makeData'
Expand Down Expand Up @@ -58,7 +57,7 @@ export function App() {
// 7. Create the table instance with the required columns and data.
// Features and row models are already defined in the createTableHook call above
const table = createAppTable({
key: 'basic-app-table', // needed for devtools
key: 'basic-app-table',
debugTable: true,
columns,
get data() {
Expand All @@ -67,8 +66,6 @@ export function App() {
// add additional table options here or in the createTableHook call above
})

useTanStackTableDevtools(table)

// 8. Render your table markup from the table instance APIs
return (
<div class="demo-root">
Expand Down
Loading