Skip to content

Commit bec8968

Browse files
authored
chore: _rowModels refactor (#5649)
* start row model refactor to be like feature options * update some examples * update react examples with new row models
1 parent fab3f1d commit bec8968

File tree

143 files changed

+843
-709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+843
-709
lines changed

docs/api/features/column-filtering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Example:
357357
import { getFilteredRowModel } from '@tanstack/[adapter]-table'
358358

359359

360-
getFilteredRowModel: getFilteredRowModel(),
360+
getFilteredRowModel: createFilteredRowModel(),
361361
})
362362
```
363363

docs/api/features/global-filtering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Example:
197197
```tsx
198198
import { getFilteredRowModel } from '@tanstack/[adapter]-table'
199199

200-
getFilteredRowModel: getFilteredRowModel(),
200+
getFilteredRowModel: createFilteredRowModel(),
201201
})
202202
```
203203

docs/api/features/pagination.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type PaginationInitialTableState = {
3030
manualPagination?: boolean
3131
```
3232
33-
Enables manual pagination. If this option is set to `true`, the table will not automatically paginate rows using `getPaginationRowModel()` and instead will expect you to manually paginate the rows before passing them to the table. This is useful if you are doing server-side pagination and aggregation.
33+
Enables manual pagination. If this option is set to `true`, the table will not automatically paginate rows using `getPaginatedRowModel()` and instead will expect you to manually paginate the rows before passing them to the table. This is useful if you are doing server-side pagination and aggregation.
3434
3535
### `pageCount`
3636
@@ -66,10 +66,10 @@ onPaginationChange?: OnChangeFn<PaginationState>
6666
6767
If this function is provided, it will be called when the pagination state changes and you will be expected to manage the state yourself. You can pass the managed state back to the table via the `tableOptions.state.pagination` option.
6868
69-
### `getPaginationRowModel`
69+
### `getPaginatedRowModel`
7070
7171
```tsx
72-
getPaginationRowModel?: (table: Table<TData>) => () => RowModel<TData>
72+
getPaginatedRowModel?: (table: Table<TData>) => () => RowModel<TData>
7373
```
7474
7575
Returns the row model after pagination has taken place, but no further.
@@ -198,10 +198,10 @@ getPrePaginationRowModel: () => RowModel<TData>
198198
199199
Returns the row model for the table before any pagination has been applied.
200200
201-
### `getPaginationRowModel`
201+
### `getPaginatedRowModel`
202202
203203
```tsx
204-
getPaginationRowModel: () => RowModel<TData>
204+
getPaginatedRowModel: () => RowModel<TData>
205205
```
206206
207207
Returns the row model for the table after pagination has been applied.

docs/framework/angular/angular-table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class AppComponent {
2222
table = injectTable(() => ({
2323
data: this.data(),
2424
columns: defaultColumns,
25-
getCoreRowModel: getCoreRowModel(),
25+
getCoreRowModel: createCoreRowModel(),
2626
}))
2727
}
2828

docs/framework/lit/guide/table-state.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class MyComponent extends LitElement {
9090
this._sorting = updaterOrValue
9191
}
9292
},
93-
getSortedRowModel: getSortedRowModel(),
94-
getCoreRowModel: getCoreRowModel(),
93+
getSortedRowModel: createSortedRowModel(),
94+
getCoreRowModel: createCoreRowModel(),
9595
})
9696

9797
return html`...`
@@ -117,8 +117,8 @@ render() {
117117
const table = this.tableController.table({
118118
columns,
119119
data,
120-
getCoreRowModel: getCoreRowModel(),
121-
getSortedRowModel: getSortedRowModel()
120+
getCoreRowModel: createCoreRowModel(),
121+
getSortedRowModel: createSortedRowModel()
122122
})
123123
const state = { ...table.initialState, ...this._tableState };
124124
table.setOptions(prev => ({
@@ -160,8 +160,8 @@ render() {
160160
this._sorting = updaterOrValue
161161
}
162162
},
163-
getSortedRowModel: getSortedRowModel(),
164-
getCoreRowModel: getCoreRowModel(),
163+
getSortedRowModel: createSortedRowModel(),
164+
getCoreRowModel: createCoreRowModel(),
165165
})
166166

167167
return html`...`;

docs/framework/svelte/svelte-table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Example:
6666
const table = createTable({
6767
data: peopleData,
6868
columns,
69-
getCoreRowModel: getCoreRowModel()
69+
getCoreRowModel: createCoreRowModel()
7070
})
7171
</script>
7272

docs/guide/column-faceting.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import {
3232
const table = useTable({
3333
columns,
3434
data,
35-
getCoreRowModel: getCoreRowModel(),
36-
getFacetedRowModel: getFacetedRowModel(), //if you need a list of values for a column (other faceted row models depend on this one)
35+
getCoreRowModel: createCoreRowModel(),
36+
getFacetedRowModel: createFacetedRowModel(), //if you need a list of values for a column (other faceted row models depend on this one)
3737
getFacetedMinMaxValues: getFacetedMinMaxValues(), //if you need min/max values
3838
getFacetedUniqueValues: getFacetedUniqueValues(), //if you need a list of unique values
3939
//...
@@ -71,8 +71,8 @@ const facetingQuery = useQuery(
7171
const table = useTable({
7272
columns,
7373
data,
74-
getCoreRowModel: getCoreRowModel(),
75-
getFacetedRowModel: getFacetedRowModel(),
74+
getCoreRowModel: createCoreRowModel(),
75+
getFacetedRowModel: createFacetedRowModel(),
7676
getFacetedUniqueValues: (table, columnId) => {
7777
const uniqueValueMap = new Map<string, number>();
7878
//...

docs/guide/column-filtering.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ No `getFilteredRowModel` table option is needed for manual server-side filtering
5353
const table = useTable({
5454
data,
5555
columns,
56-
getCoreRowModel: getCoreRowModel(),
57-
// getFilteredRowModel: getFilteredRowModel(), // not needed for manual server-side filtering
56+
getCoreRowModel: createCoreRowModel(),
57+
// getFilteredRowModel: createFilteredRowModel(), // not needed for manual server-side filtering
5858
manualFiltering: true,
5959
})
6060
```
@@ -71,8 +71,8 @@ import { useTable, getFilteredRowModel } from '@tanstack/react-table'
7171
const table = useTable({
7272
data,
7373
columns,
74-
getCoreRowModel: getCoreRowModel(),
75-
getFilteredRowModel: getFilteredRowModel(), // needed for client-side filtering
74+
getCoreRowModel: createCoreRowModel(),
75+
getFilteredRowModel: createFilteredRowModel(), // needed for client-side filtering
7676
})
7777
```
7878

@@ -215,8 +215,8 @@ const columns = [
215215
const table = useTable({
216216
columns,
217217
data,
218-
getCoreRowModel: getCoreRowModel(),
219-
getFilteredRowModel: getFilteredRowModel(),
218+
getCoreRowModel: createCoreRowModel(),
219+
getFilteredRowModel: createFilteredRowModel(),
220220
filterFns: { // add a custom global filter function
221221
myCustomFilterFn: (row, columnId, filterValue) => { // defined inline here
222222
return // true or false based on your custom logic
@@ -295,9 +295,9 @@ However, if you want to allow sub-rows to be filtered and searched through, rega
295295
const table = useTable({
296296
columns,
297297
data,
298-
getCoreRowModel: getCoreRowModel(),
299-
getFilteredRowModel: getFilteredRowModel(),
300-
getExpandedRowModel: getExpandedRowModel(),
298+
getCoreRowModel: createCoreRowModel(),
299+
getFilteredRowModel: createFilteredRowModel(),
300+
getExpandedRowModel: createExpandedRowModel(),
301301
filterFromLeafRows: true, // filter and search through sub-rows
302302
})
303303
```
@@ -312,9 +312,9 @@ Use `maxLeafRowFilterDepth: 0` if you want to preserve a parent row's sub-rows f
312312
const table = useTable({
313313
columns,
314314
data,
315-
getCoreRowModel: getCoreRowModel(),
316-
getFilteredRowModel: getFilteredRowModel(),
317-
getExpandedRowModel: getExpandedRowModel(),
315+
getCoreRowModel: createCoreRowModel(),
316+
getFilteredRowModel: createFilteredRowModel(),
317+
getExpandedRowModel: createExpandedRowModel(),
318318
maxLeafRowFilterDepth: 0, // only filter root level parent rows out
319319
})
320320
```

docs/guide/pagination.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ Alternatively, instead of paginating the data, you can render all rows of a larg
4949
If you want to take advantage of the built-in client-side pagination in TanStack Table, you first need to pass in the pagination row model.
5050

5151
```jsx
52-
import { useTable, getCoreRowModel, getPaginationRowModel } from '@tanstack/react-table';
52+
import { useTable, getCoreRowModel, getPaginatedRowModel } from '@tanstack/react-table';
5353
//...
5454
const table = useTable({
5555
columns,
5656
data,
57-
getCoreRowModel: getCoreRowModel(),
58-
getPaginationRowModel: getPaginationRowModel(), //load client-side pagination code
57+
getCoreRowModel: createCoreRowModel(),
58+
getPaginatedRowModel: createPaginatedRowModel(), //load client-side pagination code
5959
});
6060
```
6161

@@ -70,13 +70,13 @@ No pagination row model is needed for server-side pagination, but if you have pr
7070
The table instance will have no way of knowing how many rows/pages there are in total in your back-end unless you tell it. Provide either the `rowCount` or `pageCount` table option to let the table instance know how many pages there are in total. If you provide a `rowCount`, the table instance will calculate the `pageCount` internally from `rowCount` and `pageSize`. Otherwise, you can directly provide the `pageCount` if you already have it. If you don't know the page count, you can just pass in `-1` for the `pageCount`, but the `getCanNextPage` and `getCanPreviousPage` row model functions will always return `true` in this case.
7171

7272
```jsx
73-
import { useTable, getCoreRowModel, getPaginationRowModel } from '@tanstack/react-table';
73+
import { useTable, getCoreRowModel, getPaginatedRowModel } from '@tanstack/react-table';
7474
//...
7575
const table = useTable({
7676
columns,
7777
data,
78-
getCoreRowModel: getCoreRowModel(),
79-
// getPaginationRowModel: getPaginationRowModel(), //not needed for server-side pagination
78+
getCoreRowModel: createCoreRowModel(),
79+
// getPaginatedRowModel: createPaginatedRowModel(), //not needed for server-side pagination
8080
manualPagination: true, //turn off client-side pagination
8181
rowCount: dataQuery.data?.rowCount, //pass in the total row count so the table knows how many pages there are (pageCount calculated internally if not provided)
8282
// pageCount: dataQuery.data?.pageCount, //alternatively directly pass in pageCount instead of rowCount
@@ -97,7 +97,7 @@ The `pagination` state is an object that contains the following properties:
9797
You can manage the `pagination` state just like any other state in the table instance.
9898
9999
```jsx
100-
import { useTable, getCoreRowModel, getPaginationRowModel } from '@tanstack/react-table';
100+
import { useTable, getCoreRowModel, getPaginatedRowModel } from '@tanstack/react-table';
101101
//...
102102
const [pagination, setPagination] = useState({
103103
pageIndex: 0, //initial page index
@@ -107,8 +107,8 @@ const [pagination, setPagination] = useState({
107107
const table = useTable({
108108
columns,
109109
data,
110-
getCoreRowModel: getCoreRowModel(),
111-
getPaginationRowModel: getPaginationRowModel(),
110+
getCoreRowModel: createCoreRowModel(),
111+
getPaginatedRowModel: createPaginatedRowModel(),
112112
onPaginationChange: setPagination, //update the pagination state when internal APIs mutate the pagination state
113113
state: {
114114
//...
@@ -123,8 +123,8 @@ Alternatively, if you have no need for managing the `pagination` state in your o
123123
const table = useTable({
124124
columns,
125125
data,
126-
getCoreRowModel: getCoreRowModel(),
127-
getPaginationRowModel: getPaginationRowModel(),
126+
getCoreRowModel: createCoreRowModel(),
127+
getPaginatedRowModel: createPaginatedRowModel(),
128128
initialState: {
129129
pagination: {
130130
pageIndex: 2, //custom initial page index
@@ -148,8 +148,8 @@ By default, `pageIndex` is reset to `0` when page-altering state changes occur,
148148
const table = useTable({
149149
columns,
150150
data,
151-
getCoreRowModel: getCoreRowModel(),
152-
getPaginationRowModel: getPaginationRowModel(),
151+
getCoreRowModel: createCoreRowModel(),
152+
getPaginatedRowModel: createPaginatedRowModel(),
153153
autoResetPageIndex: false, //turn off auto reset of pageIndex
154154
});
155155
```

docs/guide/row-models.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { getCoreRowModel, useTable } from '@tanstack/react-table'
1111

1212
function Component() {
1313
const table = useTable({
14-
data,
1514
columns,
16-
getCoreRowModel: getCoreRowModel(), //row model
15+
data,
16+
getCoreRowModel: createCoreRowModel(), //row model
1717
})
1818
}
1919
```
@@ -40,22 +40,22 @@ import {
4040
getFacetedUniqueValues,
4141
getFilteredRowModel,
4242
getGroupedRowModel,
43-
getPaginationRowModel,
43+
getPaginatedRowModel,
4444
getSortedRowModel,
4545
}
4646
//...
4747
const table = useTable({
4848
columns,
4949
data,
50-
getCoreRowModel: getCoreRowModel(),
51-
getExpandedRowModel: getExpandedRowModel(),
50+
getCoreRowModel: createCoreRowModel(),
51+
getExpandedRowModel: createExpandedRowModel(),
5252
getFacetedMinMaxValues: getFacetedMinMaxValues(),
53-
getFacetedRowModel: getFacetedRowModel(),
53+
getFacetedRowModel: createFacetedRowModel(),
5454
getFacetedUniqueValues: getFacetedUniqueValues(),
55-
getFilteredRowModel: getFilteredRowModel(),
56-
getGroupedRowModel: getGroupedRowModel(),
57-
getPaginationRowModel: getPaginationRowModel(),
58-
getSortedRowModel: getSortedRowModel(),
55+
getFilteredRowModel: createFilteredRowModel(),
56+
getGroupedRowModel: createGroupedRowModel(),
57+
getPaginatedRowModel: createPaginatedRowModel(),
58+
getSortedRowModel: createSortedRowModel(),
5959
})
6060
```
6161
@@ -87,7 +87,7 @@ For normal rendering use cases, you will probably only need to use the `table.ge
8787
- `getExpandedRowModel` - returns a row model that accounts for expanded/hidden sub-rows.
8888
- `getPreExpandedRowModel` - returns a row model that only includes root level rows with no expanded sub-rows included. Still includes sorting.
8989
90-
- `getPaginationRowModel` - returns a row model that only includes the rows that should be displayed on the current page based on the pagination state.
90+
- `getPaginatedRowModel` - returns a row model that only includes the rows that should be displayed on the current page based on the pagination state.
9191
- `getPrePaginationRowModel` - returns a row model without pagination applied (includes all rows).
9292
9393
- `getSelectedRowModel` - returns a row model of all selected rows (but only based on the data that was passed to the table). Runs after getCoreRowModel.
@@ -101,7 +101,7 @@ Knowing how TanStack Table processes rows internally can help you gain a better
101101
102102
Internally, this is the order in which each of the row models are applied to the data, if their respective features are enabled:
103103
104-
`getCoreRowModel` -> `getFilteredRowModel` -> `getGroupedRowModel` -> `getSortedRowModel` -> `getExpandedRowModel` -> `getPaginationRowModel` -> `getRowModel`
104+
`getCoreRowModel` -> `getFilteredRowModel` -> `getGroupedRowModel` -> `getSortedRowModel` -> `getExpandedRowModel` -> `getPaginatedRowModel` -> `getRowModel`
105105
106106
If in any case the respective feature is disabled or turned off with a `"manual*"` table option, the `getPre*RowModel` will be used instead in that step of the process.
107107

0 commit comments

Comments
 (0)