You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/guide/row-models.md
+65-2
Original file line number
Diff line number
Diff line change
@@ -20,13 +20,18 @@ function Component() {
20
20
21
21
What is this `getCoreRowModel` function? And why do you have to import it from TanStack Table only to just pass it back to itself?
22
22
23
-
Well the answer is that TanStack Table is a modular library. Not all code for every single feature is included in the createTable functions/hooks by default. You only need to import and include the code that you will need to correctly generate rows based on the features you want to use.
23
+
Well, the answer is that TanStack Table is a modular library. Not all code for every single feature is included in the createTable functions/hooks by default. You only need to import and include the code that you will need to correctly generate rows based on the features you want to use.
24
+
25
+
### What are Row Models?
26
+
27
+
Row models run under the hood of TanStack Table to transform your original data in useful ways that are needed for data grid features like filtering, sorting, grouping, expanding, and pagination. The rows that get generated and render on screen won't necessarily be a 1:1 mapping of the original data that you passed to the table. They may be sorted, filtered, paginated, etc.
24
28
25
29
### Import Row Models
26
30
27
31
You should only import the row models that you need. Here are all of the row models that are available:
28
32
29
33
```ts
34
+
//only import the row models you need
30
35
import {
31
36
getCoreRowModel,
32
37
getExpandedRowModel,
@@ -56,4 +61,62 @@ const table = useReactTable({
56
61
57
62
### Customize/Fork Row Models
58
63
59
-
You don't have to use the exact row models that are provided by TanStack Table. If you need some advanced customization for certain row models, feel free to copy the [source code](https://github.com/TanStack/table/tree/main/packages/table-core/src/utils) for the row model you want to customize and modify it to your needs.
64
+
You don't have to use the exact row models that are provided by TanStack Table. If you need some advanced customization for certain row models, feel free to copy the [source code](https://github.com/TanStack/table/tree/main/packages/table-core/src/utils) for the row model you want to customize and modify it to your needs.
65
+
66
+
### Using Row Models
67
+
68
+
Once your table instance has been created, you can access all of the row models that you may need directly from the table instance. There are even more derived row models available apart from the ones that you may have imported.
69
+
70
+
For normal rendering use cases, you will probably only need to use the `table.getRowModel()` method, as this row model will use all/any of the other row models depending on which features you have enabled or disabled. All of the other row models are available for you to "dig into" some of the underlying data transformations that are happening in the table.
71
+
72
+
### Available Row Models on Table Instance
73
+
74
+
- **`getRowModel`** - This is the main row model that you should use for rendering your table rows markup. It will use all of the other row models to generate the final row model that you will use to render your table rows.
75
+
76
+
- `getCoreRowModel` - returns a basic row model that is just a 1:1 mapping of the original data passed to the table.
77
+
78
+
- `getFilteredRowModel` - returns a row model that accounts for column filtering and global filtering.
79
+
- `getPreFilteredRowModel` - returns a row model before column filtering and global filtering are applied.
80
+
81
+
- `getGroupedRowModel` - returns a row model that applies grouping and aggregation to the data and creates sub-rows.
82
+
- `getPreGroupedRowModel` - returns a row model before grouping and aggregation are applied.
83
+
84
+
- `getSortedRowModel` - returns a row model that has had sorting applied to it.
85
+
- `getPreSortedRowModel` - returns a row model before sorting is applied (rows are in original order).
86
+
87
+
- `getExpandedRowModel` - returns a row model that accounts for expanded/hidden sub-rows.
88
+
- `getPreExpandedRowModel` - returns a row model that only includes root level rows with no expanded sub-rows included. Still includes sorting.
89
+
90
+
- `getPaginationRowModel` - returns a row model that only includes the rows that should be displayed on the current page based on the pagination state.
91
+
- `getPrePaginationRowModel` - returns a row model without pagination applied (includes all rows).
92
+
93
+
- `getSelectedRowModel` - returns a row model of all selected rows (but only based on the `data` that was passed to the table). Runs after `getCoreRowModel`.
94
+
- `getPreSelectedRowModel` - returns a row model before row selection is applied (Just returns `getCoreRowModel`).
95
+
- `getGroupedSelectedRowModel` - returns a row model of selected rows after grouping. Runs after `getSortedRowModel`, which runs after `getGroupedRowModel`, which runs after `getFilteredRowModel`.
96
+
- `getFilteredSelectedRowModel` - returns a row model of selected rows after column filtering and global filtering. Runs after `getFilteredRowModel`.
97
+
98
+
### The Order of Row Model Execution
99
+
100
+
Knowing how TanStack Table processes rows internally can help you gain a better understanding of what is happening under the hood, and help you debug any issues you may encounter.
101
+
102
+
Internally, this is the order in which each of the row models are applied to the data, if their respective features are enabled:
0 commit comments