Row Numbers Feature Guide
Material React Table has an easy to implement row number features. There are two row number modes that you can enable. You can have row numbers that are associated with the data in the table (original mode), or you can have row numbers that are just statically part of the table (static mode).
Relevant Props
# | Prop Name | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 |
| Row Numbers Feature Guide | |||
2 |
|
| |||
Enable Row Numbers (Original Mode)
In the default rowNumberMode (original
), the row numbers linked to the original index of the data array. This means that when you search or filter, the same row numbers will stay with the row, though they will not be in the same order when sorted or will skip numbers when filtered.
# | First Name | Last Name | Address | City | State |
---|---|---|---|---|---|
1 | Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky |
2 | Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio |
3 | Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia |
4 | Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska |
5 | Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1import React, { useMemo } from 'react';2import MaterialReactTable, { MRT_ColumnDef } from 'material-react-table';3import { data, Person } from './makeData';45const Example = () => {6 const columns = useMemo<MRT_ColumnDef<Person>[]>(7 //column definitions...32 );3334 return (35 <MaterialReactTable36 columns={columns}37 data={data}38 enableRowNumbers39 rowNumberMode="original" //default40 />41 );42};4344export default Example;45
Enable Row Numbers (Static Mode)
Alternatively, if you just want row numbers to always be the same and in order, you can use the static
row number mode.
# | First Name | Last Name | Address | City | State |
---|---|---|---|---|---|
1 | Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky |
2 | Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio |
3 | Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia |
4 | Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska |
5 | Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1import React, { useMemo } from 'react';2import MaterialReactTable, { MRT_ColumnDef } from 'material-react-table';3import { data, Person } from './makeData';45const Example = () => {6 const columns = useMemo<MRT_ColumnDef<Person>[]>(7 () => [8 //column definitions...30 ],3132 [],33 );3435 return (36 <MaterialReactTable37 columns={columns}38 data={data}39 enableRowNumbers40 rowNumberMode="static"41 />42 );43};4445export default Example;46
View Extra Storybook Examples