Skip to content

Commit b327934

Browse files
authoredJan 4, 2024
docs: refactor guides section and new table instance guide (#5254)
* update readme * refactor guide section, table instance guide * prettier
1 parent 80d92d6 commit b327934

28 files changed

+566
-267
lines changed
 

‎README.md

+28-70
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,41 @@ Headless UI for building **powerful tables & datagrids** for **React, Solid, Vue
66

77
<a href="https://twitter.com/intent/tweet?button_hashtag=TanStack" target="\_parent">
88
<img alt="#TanStack" src="https://img.shields.io/twitter/url?color=%2308a0e9&label=%23TanStack&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Fbutton_hashtag%3DTanStack" />
9-
</a><a href="https://github.com/tanstack/table/actions?table=workflow%3A%22react-table+tests%22">
10-
<img src="https://github.com/tanstack/table/workflows/react-table%20tests/badge.svg" />
11-
</a><a href="https://npmjs.com/package/@tanstack/react-table" target="\_parent">
9+
</a>
10+
<a href="https://github.com/tanstack/table/actions?table=workflow%3A%22react-table+tests%22">
11+
<img src="https://github.com/tanstack/table/workflows/react-table%20tests/badge.svg" />
12+
</a>
13+
<a href="https://npmjs.com/package/@tanstack/react-table" target="\_parent">
1214
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/react-table.svg" />
13-
</a><a href="https://bundlephobia.com/result?p=@tanstack/react-table@latest" target="\_parent">
15+
</a>
16+
<a href="https://bundlephobia.com/result?p=@tanstack/react-table@latest" target="\_parent">
1417
<img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/react-table@latest" />
15-
</a><a href="#badge">
16-
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
17-
</a><a href="https://github.com/tanstack/table/discussions">
18+
</a>
19+
<a href="#badge">
20+
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
21+
</a>
22+
<a href="https://github.com/tanstack/table/discussions">
1823
<img alt="Join the discussion on Github" src="https://img.shields.io/badge/Github%20Discussions%20%26%20Support-Chat%20now!-blue" />
19-
</a><a href="https://github.com/tanstack/table" target="\_parent">
24+
</a>
25+
<a href="https://github.com/tanstack/table" target="\_parent">
2026
<img alt="" src="https://img.shields.io/github/stars/tanstack/react-table.svg?style=social&label=Star" />
21-
</a><a href="https://twitter.com/tannerlinsley" target="\_parent">
27+
</a>
28+
<a href="https://twitter.com/tannerlinsley" target="\_parent">
2229
<img alt="" src="https://img.shields.io/twitter/follow/tannerlinsley.svg?style=social&label=Follow" />
2330
</a>
2431

2532
> [Looking for version 7 of `react-table`? Click here!](https://github.com/tanstack/table/tree/v7)
2633
2734
## Enjoy this library?
2835

29-
Try some other [TanStack](https://tanstack.com) like [React Query](https://github.com/TanStack/query), [React Form](https://github.com/tannerlinsley/react-form), [React Charts](https://github.com/TanStack/react-charts)
36+
Try other [TanStack](https://tanstack.com) libraries:
37+
38+
- [TanStack Query](https://github.com/TanStack/query) <img alt="" src="https://img.shields.io/github/stars/tanstack/query.svg" />
39+
- [TanStack Table](https://github.com/TanStack/table) <img alt="" src="https://img.shields.io/github/stars/tanstack/table.svg" />
40+
- [TanStack Router](https://github.com/TanStack/router) <img alt="" src="https://img.shields.io/github/stars/tanstack/router.svg" />
41+
- [TanStack Virtual](https://github.com/TanStack/virtual) <img alt="" src="https://img.shields.io/github/stars/tanstack/virtual.svg" />
42+
- [TanStack Form](https://github.com/TanStack/form) <img alt="" src="https://img.shields.io/github/stars/tanstack/form.svg" />
43+
- [TanStack Ranger](https://github.com/TanStack/ranger) <img alt="" src="https://img.shields.io/github/stars/tanstack/ranger.svg" />
3044

3145
## Visit [tanstack.com/table](https://tanstack.com/table) for docs, guides, API and more!
3246

@@ -55,7 +69,7 @@ JS/TS ecosystem and every use-case.
5569

5670
- Agnostic core (JS/TS)
5771
- 1st-class framework bindings for React, Vue, Solid
58-
- ~14kb or less (with tree-shaking)
72+
- ~15kb or less (with tree-shaking)
5973
- 100% TypeScript (but not required)
6074
- Headless (100% customizable, Bring-your-own-UI)
6175
- Auto out of the box, opt-in controllable state
@@ -92,73 +106,18 @@ There are a fair amount of breaking changes (they're worth it, trust us!):
92106
- Plugin system has been removed so plugins must be rewritten to wrap/compose the new functional API. Contact us if you need help!
93107
- Column configuration options have changed, but only slightly.
94108
- Table options are mostly the same, with some larger changes around optional state management/control and data pipeline control
95-
- The `tableInstance` while similar in spirit to v7 has been reconfigured to be much faster.
96-
97-
## Todo (in order of priority)
98-
99-
- [x] Rewrite Core
100-
- [x] Core
101-
- [x] Columns
102-
- [x] Headers
103-
- [x] Visibility
104-
- [x] Pinning
105-
- [x] Filters
106-
- [x] Sorting
107-
- [x] Grouping
108-
- [x] Expanding
109-
- [x] Column Sizing
110-
- [x] Pagination
111-
- [x] Row Selection
112-
- [ ] Migrate [Examples](https://github.com/tanstack/table/tree/main/examples)
113-
- [x] column-visibility
114-
- [x] column-ordering
115-
- [x] column-pinning
116-
- [x] basic
117-
- [x] filters
118-
- [x] sorting
119-
- [x] pagination
120-
- [x] pagination-controlled
121-
- [x] column-sizing
122-
- [x] row-selection
123-
- [x] expanding
124-
- [x] grouping-and-aggregation
125-
- [x] editable-data
126-
- [ ] kitchen-sink
127-
- [x] row-dnd
128-
- [ ] streaming-rows
129-
- [x] sub-components
130-
- [x] virtualized-rows
131-
- [ ] absolute-layout
132-
- [ ] block-layout
133-
- [ ] animated-framer-motion
134-
- [x] bootstrap
135-
- [ ] bootstrap-ui-components
136-
- [ ] data-driven-classes-and-styles
137-
- [x] full-width-resizable-table
138-
- [x] full-width-table
139-
- [ ] material-ui-components
140-
- [ ] material-UI-enhanced-table
109+
- The `table` instance while similar in spirit to v7 has been reconfigured to be much faster.
141110

142111
## Installation
143112

113+
Install one of the following packages based on your framework of choice:
114+
144115
```bash
145116
# Npm
146117
npm install @tanstack/react-table
147118
npm install @tanstack/solid-table
148119
npm install @tanstack/vue-table
149120
npm install @tanstack/svelte-table
150-
151-
#pnpm
152-
pnpm install @tanstack/react-table
153-
pnpm install @tanstack/solid-table
154-
pnpm install @tanstack/vue-table
155-
pnpm install @tanstack/svelte-table
156-
157-
#Yarn
158-
yarn add @tanstack/react-table
159-
yarn add @tanstack/solid-table
160-
yarn add @tanstack/vue-table
161-
yarn add @tanstack/svelte-table
162121
```
163122

164123
## How to help?
@@ -168,7 +127,6 @@ yarn add @tanstack/svelte-table
168127
- Introspect the types! Even without the docs finished, the library ships with 100% typescript to help you explore its capabilities.
169128
- [Read the contribution guidelines](https://github.com/tanstack/table/tree/main/CONTRIBUTING.md)
170129
- Write some docs! Start with the [API docs](https://github.com/TanStack/react-table/tree/main/docs/api) and try adding some information about one or more of the features. The types do a decent job of showing what's supported and the capabilities of the library.
171-
- Try your hand at migrating an example to v8! The todo list for the examples is above!
172130
- **Using a plugin?** Try rewriting your plugin (v8 doesn't have a plugin system any more) as a functional wrapper that uses TanStack Table internally. The new API is much more powerful and easier to compose. If you find something you can't figure out, let us know and we'll add it to the API.
173131

174132
### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/)

‎docs/api/core/header.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ The depth of the header, zero-indexed based.
3838
column: Column<TData>
3939
```
4040

41-
The header's associated [Column](./column.md) object
41+
The header's associated [Column](./column) object
4242

4343
### `headerGroup`
4444

4545
```tsx
4646
headerGroup: HeaderGroup<TData>
4747
```
4848

49-
The header's associated [HeaderGroup](./header-group.md) object
49+
The header's associated [HeaderGroup](./header-group) object
5050

5151
### `subHeaders`
5252

‎docs/api/core/row.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,4 @@ An array of the original subRows as returned by the `options.getSubRows` option.
120120
type getAllCells = () => Cell<TData>[]
121121
```
122122
123-
Returns all of the [Cells](./cell.md) for the row.
123+
Returns all of the [Cells](./cell) for the row.

‎docs/config.json

+26-6
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@
4949
"label": "Migrating to V8",
5050
"to": "guide/migrating"
5151
},
52+
{
53+
"label": "Tables (Getting Started)",
54+
"to": "guide/tables"
55+
},
5256
{
5357
"label": "Column Defs",
5458
"to": "guide/column-defs"
5559
},
5660
{
57-
"label": "Tables",
58-
"to": "guide/tables"
61+
"label": "Rows Models",
62+
"to": "guide/row-models"
5963
},
6064
{
6165
"label": "Rows",
@@ -77,6 +81,10 @@
7781
"label": "Column Ordering",
7882
"to": "guide/column-ordering"
7983
},
84+
{
85+
"label": "Column Pinning",
86+
"to": "guide/column-pinning"
87+
},
8088
{
8189
"label": "Column Sizing",
8290
"to": "guide/column-sizing"
@@ -86,8 +94,20 @@
8694
"to": "guide/column-visibility"
8795
},
8896
{
89-
"label": "Filters",
90-
"to": "guide/filters"
97+
"label": "Column Filtering",
98+
"to": "guide/column-filtering"
99+
},
100+
{
101+
"label": "Global Filtering",
102+
"to": "guide/global-filtering"
103+
},
104+
{
105+
"label": "Fuzzy Filtering",
106+
"to": "guide/fuzzy-filtering"
107+
},
108+
{
109+
"label": "Faceted Values",
110+
"to": "guide/faceted-values"
91111
},
92112
{
93113
"label": "Sorting",
@@ -106,8 +126,8 @@
106126
"to": "guide/pagination"
107127
},
108128
{
109-
"label": "Pinning",
110-
"to": "guide/pinning"
129+
"label": "Row Pinning",
130+
"to": "guide/row-pinning"
111131
},
112132
{
113133
"label": "Row Selection",

‎docs/guide/column-filtering.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Column Filtering
3+
---
4+
5+
## Examples
6+
7+
Want to skip to the implementation? Check out these examples:
8+
9+
- [filters](../examples/react/filters) (includes faceting)
10+
- [editable-data](../examples/react/editable-data)
11+
- [expanding](../examples/react/expanding)
12+
- [grouping](../examples/react/grouping)
13+
- [pagination](../examples/react/pagination)
14+
- [row-selection](../examples/react/row-selection)
15+
16+
## API
17+
18+
[Filters API](../api/features/filters)
19+
20+
## Column Filtering Guide
21+
22+
Filtering comes in 2 flavors: Column Filtering and Global Filtering.
23+
24+
This guide will focus on column filtering, which is a filter that is applied to a single column's accessor value.

‎docs/guide/column-ordering.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Want to skip to the implementation? Check out these examples:
1212

1313
[Column Ordering API](../api/features/column-ordering)
1414

15-
## Overview
15+
## Column Ordering Guide
1616

1717
There are 3 table features that can reorder columns, which happen in the following order:
1818

‎docs/guide/column-pinning.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Column Pinning
3+
---
4+
5+
## Examples
6+
7+
Want to skip to the implementation? Check out these examples:
8+
9+
- [column-pinning](../examples/react/column-pinning)
10+
- [row-pinning](../examples/react/row-pinning)
11+
12+
## API
13+
14+
[Pinning API](../api/features/pinning)
15+
16+
## Column Pinning Guide
17+
18+
There are 3 table features that can reorder columns, which happen in the following order:
19+
20+
1. **Column Pinning** - If pinning, columns are split into left, center (unpinned), and right pinned columns.
21+
2. Manual [Column Ordering](../guide/column-ordering) - A manually specified column order is applied.
22+
3. [Grouping](../guide/grouping) - If grouping is enabled, a grouping state is active, and `tableOptions.columnGroupingMode` is set to `'reorder' | 'remove'`, then the grouped columns are reordered to the start of the column flow.

‎docs/guide/column-sizing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Want to skip to the implementation? Check out these examples:
1313

1414
[Column Sizing API](../api/features/column-sizing)
1515

16-
## Guide
16+
## Column Sizing Guide
1717

1818
The column sizing feature allows you to optionally specify the width of each column including min and max widths. It also allows you and your users the ability to dynamically change the width of all columns at will, eg. by dragging the column headers.
1919

‎docs/guide/column-visibility.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Want to skip to the implementation? Check out these examples:
1212
## API
1313

1414
[Column Visibility API](../api/features/column-visibility)
15+
16+
## Column Visibility Guide

‎docs/guide/expanding.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Want to skip to the implementation? Check out these examples:
1212
## API
1313

1414
[Expanding API](../api/features/expanding)
15+
16+
## Expanding Feature Guide

‎docs/guide/faceted-values.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Faceted Values
3+
---
4+
5+
## Examples
6+
7+
Want to skip to the implementation? Check out these examples:
8+
9+
- [filters](../examples/react/filters) (includes faceting)
10+
11+
## API
12+
13+
[Filters API](../api/features/filters)
14+
15+
## Faceted Values Guide

‎docs/guide/features.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ title: Features
44

55
TanStack Table comes with many features, each with their own associated options and API:
66

7-
- [Column Visibility](./guide/column-visibility)
87
- [Column Ordering](./guide/column-ordering)
98
- [Column Pinning](./guide/column-pinning)
109
- [Column Sizing](./guide/column-sizing)
10+
- [Column Visibility](./guide/column-visibility)
11+
- [Expanding](./guide/expanding)
1112
- [Filters](./guide/filters)
12-
- [Sorting](./guide/sorting)
1313
- [Grouping](./guide/grouping)
14-
- [Expanding](./guide/expanding)
15-
- [Row Selection](./guide/row-selection)
1614
- [Pagination](./guide/pagination)
15+
- [Row Pinning](./guide/row-pinning)
16+
- [Row Selection](./guide/row-selection)
17+
- [Sorting](./guide/sorting)

‎docs/guide/filters.md

+6-23
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,11 @@
22
title: Filters
33
---
44

5-
## Examples
5+
<!-- Deprecated -->
66

7-
Want to skip to the implementation? Check out these examples:
7+
The filter guides are now split into multiple guides:
88

9-
- [filters](../examples/react/filters) (includes faceting)
10-
- [editable-data](../examples/react/editable-data)
11-
- [expanding](../examples/react/expanding)
12-
- [grouping](../examples/react/grouping)
13-
- [pagination](../examples/react/pagination)
14-
- [row-selection](../examples/react/row-selection)
15-
16-
## API
17-
18-
[Filters API](../api/features/filters)
19-
20-
## Overview
21-
22-
Filters come in two flavors:
23-
24-
- Column filters
25-
- A filter that is applied to a single column's accessor value.
26-
- Stored in the `state.columnFilters` array as an object containing the columnId and the filter value.
27-
- Global filters
28-
- A single filter value that is applied to all or some of columns' accessor values.
29-
- Stored in the `state.globalFilter` array as any value, usually a string.
9+
- [Column Filtering](./column-filtering)
10+
- [Global Filtering](./global-filtering)
11+
- [Fuzzy Filtering](./fuzzy-filtering)
12+
- [Faceted Values](./faceted-values)

‎docs/guide/fuzzy-filtering.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Fuzzy Filtering
3+
---
4+
5+
## Examples
6+
7+
Want to skip to the implementation? Check out these examples:
8+
9+
- [filters](../examples/react/filters)
10+
11+
## API
12+
13+
[Filters API](../api/features/filters)
14+
15+
## Fuzzy Filtering Guide
16+

‎docs/guide/global-filtering.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Global Filtering
3+
---
4+
5+
## Examples
6+
7+
Want to skip to the implementation? Check out these examples:
8+
9+
- [filters](../examples/react/filters) (includes faceting)
10+
11+
## API
12+
13+
[Filters API](../api/features/filters)
14+
15+
## Overview
16+
17+
Filtering comes in 2 flavors: Column Filtering and Global Filtering.
18+
19+
This guide will focus on global filtering, which is a filter that is applied across all columns.

‎docs/guide/grouping.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Want to skip to the implementation? Check out these examples:
1212

1313
[Grouping API](../api/features/grouping)
1414

15-
## Overview
15+
## Grouping Guide
1616

1717
There are 3 table features that can reorder columns, which happen in the following order:
1818

‎docs/guide/headers.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ title: Headers
55
## API
66

77
[Header API](../api/core/header)
8+
9+
## Headers Guide

‎docs/guide/pagination.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ Want to skip to the implementation? Check out these examples:
1717
## API
1818

1919
[Pagination API](../api/features/pagination)
20+
21+
## Pagination Guide

‎docs/guide/pinning.md

+4-21
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,9 @@
22
title: Pinning
33
---
44

5-
## Examples
5+
<!-- Deprecated -->
66

7-
Want to skip to the implementation? Check out these examples:
7+
Pinning is split into 2 different feature guides:
88

9-
- [column-pinning](../examples/react/column-pinning)
10-
- [row-pinning](../examples/react/row-pinning)
11-
12-
## API
13-
14-
[Pinning API](../api/features/pinning)
15-
16-
## Overview
17-
18-
There are 3 table features that can reorder columns, which happen in the following order:
19-
20-
1. **Column Pinning** - If pinning, columns are split into left, center (unpinned), and right pinned columns.
21-
2. Manual [Column Ordering](../guide/column-ordering) - A manually specified column order is applied.
22-
3. [Grouping](../guide/grouping) - If grouping is enabled, a grouping state is active, and `tableOptions.columnGroupingMode` is set to `'reorder' | 'remove'`, then the grouped columns are reordered to the start of the column flow.
23-
24-
There are 2 table features that can reorder rows, which happen in the following order:
25-
26-
1. **Row Pinning** - If pinning, rows are split into top, center (unpinned), and bottom pinned rows.
27-
2. [Sorting](../guide/sorting)
9+
- [Column Pinning](./column-pinning)
10+
- [Row Pinning](./row-pinning)

‎docs/guide/row-models.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Row Models
3+
---

‎docs/guide/row-pinning.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Row Pinning
3+
---
4+
5+
## Examples
6+
7+
Want to skip to the implementation? Check out these examples:
8+
9+
- [row-pinning](../examples/react/row-pinning)
10+
11+
## API
12+
13+
[Pinning API](../api/features/pinning)
14+
15+
## Row Pinning Guide
16+
17+
There are 2 table features that can reorder rows, which happen in the following order:
18+
19+
1. **Row Pinning** - If pinning, rows are split into top, center (unpinned), and bottom pinned rows.
20+
2. [Sorting](../guide/sorting)

‎docs/guide/row-selection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Want to skip to the implementation? Check out these examples:
1414

1515
[Row Selection API](../api/features/row-selection)
1616

17-
## Guide
17+
## Row Selection Guide
1818

1919
The row selection feature keeps track of which rows are selected and allows you to toggle the selection of rows in a myriad of ways. Let's take a look at some common use cases.
2020

‎docs/guide/sorting.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Want to skip to the implementation? Check out these examples:
1212
## API
1313

1414
[Sorting API](../api/features/sorting)
15+
16+
## Sorting Guide

‎docs/guide/tables.md

+122
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,125 @@ title: Tables
55
## API
66

77
[Table API](../api/core/table)
8+
9+
## Table Instance Guide
10+
11+
TanStack Table is a headless UI library. When we talk about the `table` or "table instance", we're not talking about a literal `<table>` element. Instead, we're referring to the core table object that contains the table state and APIs. The `table` instance is created by calling your adapter's `createTable` function (e.g. `useReactTable`, `createSolidTable`, `createSvelteTable`, `useVueTable`).
12+
13+
### Creating a Table Instance
14+
15+
To create a table instance, 2 `options` are required: `columns` and `data`. There are dozens of other table options to configure features and behavior, but these 2 are required.
16+
17+
#### Defining Data
18+
19+
`data` is an array of objects that will be turned into the rows of your table. Each object in the array represents a row of data (under normal circumstances). If you are using TypeScript, we usually define a type for the shape of our data. This type is used as a generic type for all of the other table, column, row, and cell instances. This type is usually referred to as `TData`.
20+
21+
For example, if we have a table that displays a list of users in an array like this:
22+
23+
```json
24+
[
25+
{
26+
"firstName": "Tanner",
27+
"lastName": "Linsley",
28+
"age": 33,
29+
"visits": 100,
30+
"progress": 50,
31+
"status": "Married"
32+
},
33+
{
34+
"firstName": "Kevin",
35+
"lastName": "Vandy",
36+
"age": 27,
37+
"visits": 200,
38+
"progress": 100,
39+
"status": "Single"
40+
}
41+
]
42+
```
43+
44+
Then we can define a User (TData) type like this:
45+
46+
```ts
47+
//TData
48+
type User = {
49+
firstName: string
50+
lastName: string
51+
age: number
52+
visits: number
53+
progress: number
54+
status: string
55+
}
56+
```
57+
58+
We can then define our `data` array with this type, and then TanStack Table will be able to intelligently infer lots of types for us later on in our columns, rows, cells, etc.
59+
60+
```ts
61+
//note: data needs a "stable" reference in order to prevent infinite re-renders
62+
const data: User[] = []
63+
//or
64+
const [data, setData] = React.useState<User[]>([])
65+
//or
66+
const data = ref<User[]>([])
67+
//etc...
68+
```
69+
70+
> Note: `data` needs a "stable" reference (especially in React) in order to prevent infinite re-renders. This is why we recommend using `React.useState` or `React.useMemo`, or defining your data outside of the same react component that creates the table instance, or using a library like TanStack Query to manage your data state.
71+
72+
#### Defining Columns
73+
74+
Column definitions are covered in detail in the next section in the [Column Def Guide](./column-defs). We'll note here, however, that when you define the type of your columns, you should use the same `TData` type that you used for you data.
75+
76+
```ts
77+
const columns: ColumnDef<User>[] = [] //Pass User type as the generic TData type
78+
//or
79+
const columnHelper = createColumnHelper<User>() //Pass User type as the generic TData type
80+
```
81+
82+
The column definitions are where we will tell TanStack Table how each column should access and/or transform row data with either an `accessorKey` or `accessorFn`. See the [Column Def Guide](./column-defs#creating-accessor-columns) for more info.
83+
84+
#### Creating the Table Instance
85+
86+
With our `columns` and `data` defined, we can now create our basic table instance.
87+
88+
```ts
89+
//vanilla js
90+
const table = createTable({ columns, data })
91+
92+
//react
93+
const table = useReactTable({ columns, data })
94+
95+
//solid
96+
const table = createSolidTable({ columns, data })
97+
98+
//svelte
99+
const table = createSvelteTable({ columns, data })
100+
101+
//vue
102+
const table = useVueTable({ columns, data })
103+
```
104+
105+
So what's in the `table` instance? Let's take a look at what interactions we can have with the table instance.
106+
107+
### Table State
108+
109+
The table instance contains all of the table state, which can be accessed via the `table.getState()` API. Each table feature registers various states in the table state. For example, the row selection feature registers `rowSelection` state, the pagination feature registers `pagination` state, etc.
110+
111+
Each feature will also have corresponding state setter APIs and state resetter APIs on the table instance. For example, the row selection feature will have a `setRowSelection` API and a `resetRowSelection`.
112+
113+
```ts
114+
table.getState().rowSelection //read the row selection state
115+
table.setRowSelection((old) => ({...old})) //set the row selection state
116+
table.resetRowSelection() //reset the row selection state
117+
```
118+
119+
### Table APIs
120+
121+
There are dozens of table APIs created by each feature to help you either read or mutate the table state in different ways.
122+
123+
API reference docs for the core table instance and all other feature APIs can be found throughout the API docs.
124+
125+
For example, you can find the core table instance API docs here: [Table API](../api/core/table#table-api)
126+
127+
### Table Row Models
128+
129+
There special set of table instance APIs for reading rows out of the table instance called row models. TanStack Table has advanced features where the rows that are generated may be very different than the the array of `data` that you originally passed in. To learn more about the different row models that you can pass in as a table option, see the [Row Models Guide](./row-models).

‎docs/guide/virtualization.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Want to skip to the implementation? Check out these examples:
1515

1616
[TanStack Virtual Virtualizer API](../../../../virtual/v3/docs/api/virtualizer)
1717

18-
## Guide
18+
## Virtualization Guide
1919

2020
The TanStack Table packages do not come with any virtualization APIs or features built-in, but TanStack Table can easily work with other virtualization libraries like [react-window](https://www.npmjs.com/package/react-window) or TanStack's own [TanStack Virtual](https://tanstack.com/virtual/v3). This guide will show some strategies for using TanStack Table with TanStack Virtual.

‎examples/solid/filters/src/App.tsx

+15-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { makeData, Person } from './makeData'
1414
import ColumnFilter from './ColumnFilter'
1515
import { createSignal, For } from 'solid-js'
1616

17-
1817
const columns: ColumnDef<Person>[] = [
1918
{
2019
header: 'Name',
@@ -70,8 +69,11 @@ const columns: ColumnDef<Person>[] = [
7069
function App() {
7170
const [data, setData] = createSignal(makeData(50000))
7271
const [columnFilters, setColumnFilters] = createSignal<ColumnFiltersState>([])
73-
const [globalFilter, setGlobalFilter] = createSignal("")
74-
const debounceSetGlobalFilter = debounce((value:string) => setGlobalFilter(value), 500)
72+
const [globalFilter, setGlobalFilter] = createSignal('')
73+
const debounceSetGlobalFilter = debounce(
74+
(value: string) => setGlobalFilter(value),
75+
500
76+
)
7577
const refreshData = () => setData(makeData(50000))
7678

7779
const table = createSolidTable({
@@ -88,7 +90,7 @@ function App() {
8890
},
8991
},
9092
onGlobalFilterChange: setGlobalFilter,
91-
globalFilterFn: "includesString",
93+
globalFilterFn: 'includesString',
9294
onColumnFiltersChange: setColumnFilters,
9395
getCoreRowModel: getCoreRowModel(),
9496
getFilteredRowModel: getFilteredRowModel(),
@@ -103,11 +105,11 @@ function App() {
103105
return (
104106
<div class="p-2">
105107
<input
106-
class="p-2 font-lg shadow border border-block"
107-
value={globalFilter() ?? ""}
108-
onInput={(e) => debounceSetGlobalFilter(e.currentTarget.value)}
109-
placeholder="Search all columns..."
110-
/>
108+
class="p-2 font-lg shadow border border-block"
109+
value={globalFilter() ?? ''}
110+
onInput={e => debounceSetGlobalFilter(e.currentTarget.value)}
111+
placeholder="Search all columns..."
112+
/>
111113
<div className="h-2" />
112114
<table>
113115
<thead>
@@ -125,7 +127,10 @@ function App() {
125127
)}
126128
{header.column.getCanFilter() ? (
127129
<div>
128-
<ColumnFilter column={header.column} table={table} />
130+
<ColumnFilter
131+
column={header.column}
132+
table={table}
133+
/>
129134
</div>
130135
) : null}
131136
</>
+88-76
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,95 @@
1-
import {
2-
Column,
3-
Table,
4-
} from '@tanstack/solid-table'
5-
import { debounce } from '@solid-primitives/scheduled'
6-
import { createMemo } from 'solid-js'
1+
import { Column, Table } from '@tanstack/solid-table'
2+
import { debounce } from '@solid-primitives/scheduled'
3+
import { createMemo } from 'solid-js'
74

85
function ColumnFilter({
9-
column,
10-
table,
11-
}: {
12-
column: Column<any, unknown>
13-
table: Table<any>
14-
}) {
15-
const firstValue = table
16-
.getPreFilteredRowModel()
17-
.flatRows[0]?.getValue(column.id)
18-
19-
const columnFilterValue = column.getFilterValue()
20-
21-
const sortedUniqueValues = createMemo(
22-
() =>
23-
typeof firstValue === 'number'
24-
? []
25-
: Array.from(column.getFacetedUniqueValues().keys()).sort(),
26-
[column.getFacetedUniqueValues()]
27-
)
6+
column,
7+
table,
8+
}: {
9+
column: Column<any, unknown>
10+
table: Table<any>
11+
}) {
12+
const firstValue = table
13+
.getPreFilteredRowModel()
14+
.flatRows[0]?.getValue(column.id)
2815

29-
const debounceColumnFilter = debounce(value => column.setFilterValue(value), 500)
30-
31-
return typeof firstValue === 'number' ? (
32-
<div>
33-
<div className="flex space-x-2">
34-
<input
35-
type="number"
36-
min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')}
37-
max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')}
38-
value={(columnFilterValue as [number, number])?.[0] ?? ''}
39-
onInput={(e) => debounceColumnFilter((old: [number, number]) => [e.target.value, old?.[1]])}
40-
placeholder={`Min ${
41-
column.getFacetedMinMaxValues()?.[0]
42-
? `(${column.getFacetedMinMaxValues()?.[0]})`
43-
: ''
44-
}`}
45-
className="w-24 border shadow rounded"
46-
/>
47-
<input
48-
type="number"
49-
min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')}
50-
max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')}
51-
value={(columnFilterValue as [number, number])?.[1] ?? ''}
52-
onInput={(e) => debounceColumnFilter((old: [number, number]) => [old?.[0], e.target.value])}
53-
placeholder={`Max ${
54-
column.getFacetedMinMaxValues()?.[1]
55-
? `(${column.getFacetedMinMaxValues()?.[1]})`
56-
: ''
57-
}`}
58-
className="w-24 border shadow rounded"
59-
/>
60-
</div>
61-
<div className="h-1" />
16+
const columnFilterValue = column.getFilterValue()
17+
18+
const sortedUniqueValues = createMemo(
19+
() =>
20+
typeof firstValue === 'number'
21+
? []
22+
: Array.from(column.getFacetedUniqueValues().keys()).sort(),
23+
[column.getFacetedUniqueValues()]
24+
)
25+
26+
const debounceColumnFilter = debounce(
27+
value => column.setFilterValue(value),
28+
500
29+
)
30+
31+
return typeof firstValue === 'number' ? (
32+
<div>
33+
<div className="flex space-x-2">
34+
<input
35+
type="number"
36+
min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')}
37+
max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')}
38+
value={(columnFilterValue as [number, number])?.[0] ?? ''}
39+
onInput={e =>
40+
debounceColumnFilter((old: [number, number]) => [
41+
e.target.value,
42+
old?.[1],
43+
])
44+
}
45+
placeholder={`Min ${
46+
column.getFacetedMinMaxValues()?.[0]
47+
? `(${column.getFacetedMinMaxValues()?.[0]})`
48+
: ''
49+
}`}
50+
className="w-24 border shadow rounded"
51+
/>
52+
<input
53+
type="number"
54+
min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')}
55+
max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')}
56+
value={(columnFilterValue as [number, number])?.[1] ?? ''}
57+
onInput={e =>
58+
debounceColumnFilter((old: [number, number]) => [
59+
old?.[0],
60+
e.target.value,
61+
])
62+
}
63+
placeholder={`Max ${
64+
column.getFacetedMinMaxValues()?.[1]
65+
? `(${column.getFacetedMinMaxValues()?.[1]})`
66+
: ''
67+
}`}
68+
className="w-24 border shadow rounded"
69+
/>
6270
</div>
63-
) : (
64-
<>
65-
<datalist id={column.id + 'list'}>
66-
{sortedUniqueValues().slice(0, 5000).map((value: any) => (
71+
<div className="h-1" />
72+
</div>
73+
) : (
74+
<>
75+
<datalist id={column.id + 'list'}>
76+
{sortedUniqueValues()
77+
.slice(0, 5000)
78+
.map((value: any) => (
6779
<option value={value} key={value} />
6880
))}
69-
</datalist>
70-
<input
71-
type="text"
72-
value={(columnFilterValue ?? '') as string}
73-
onInput={(e) => debounceColumnFilter(e.target.value)}
74-
placeholder={`Search... (${column.getFacetedUniqueValues().size})`}
75-
className="w-36 border shadow rounded"
76-
list={column.id + 'list'}
77-
/>
78-
<div className="h-1" />
79-
</>
80-
)
81-
}
81+
</datalist>
82+
<input
83+
type="text"
84+
value={(columnFilterValue ?? '') as string}
85+
onInput={e => debounceColumnFilter(e.target.value)}
86+
placeholder={`Search... (${column.getFacetedUniqueValues().size})`}
87+
className="w-36 border shadow rounded"
88+
list={column.id + 'list'}
89+
/>
90+
<div className="h-1" />
91+
</>
92+
)
93+
}
8294

83-
export default ColumnFilter
95+
export default ColumnFilter

‎pnpm-lock.yaml

+135-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.