|
1 | 1 | ---
|
2 | 2 | title: Row Models
|
3 |
| ---- |
| 3 | +--- |
| 4 | + |
| 5 | +## Row Models Guide |
| 6 | + |
| 7 | +If you take a look at the most basic example of TanStack Table, you'll see a code snippet like this: |
| 8 | + |
| 9 | +```ts |
| 10 | +import { getCoreRowModel, useReactTable } from '@tanstack/react-table' |
| 11 | + |
| 12 | +function Component() { |
| 13 | + const table = useReactTable({ |
| 14 | + data, |
| 15 | + columns, |
| 16 | + getCoreRowModel: getCoreRowModel(), //row model |
| 17 | + }) |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 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 | + |
| 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 | +### Import Row Models |
| 26 | + |
| 27 | +You should only import the row models that you need. Here are all of the row models that are available: |
| 28 | + |
| 29 | +```ts |
| 30 | +import { |
| 31 | + getCoreRowModel, |
| 32 | + getExpandedRowModel, |
| 33 | + getFacetedMinMaxValues, |
| 34 | + getFacetedRowModel, |
| 35 | + getFacetedUniqueValues, |
| 36 | + getFilteredRowModel, |
| 37 | + getGroupedRowModel, |
| 38 | + getPaginationRowModel, |
| 39 | + getSortedRowModel, |
| 40 | +} |
| 41 | +//... |
| 42 | +const table = useReactTable({ |
| 43 | + data, |
| 44 | + columns, |
| 45 | + getCoreRowModel: getCoreRowModel(), |
| 46 | + getExpandedRowModel: getExpandedRowModel(), |
| 47 | + getFacetedMinMaxValues: getFacetedMinMaxValues(), |
| 48 | + getFacetedRowModel: getFacetedRowModel(), |
| 49 | + getFacetedUniqueValues: getFacetedUniqueValues(), |
| 50 | + getFilteredRowModel: getFilteredRowModel(), |
| 51 | + getGroupedRowModel: getGroupedRowModel(), |
| 52 | + getPaginationRowModel: getPaginationRowModel(), |
| 53 | + getSortedRowModel: getSortedRowModel(), |
| 54 | +}) |
| 55 | +``` |
| 56 | +
|
| 57 | +### Customize/Fork Row Models |
| 58 | +
|
| 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. |
0 commit comments