Sticky Row Pinning Example
Material React Table has the ability to pin rows and keep them in view while scrolling. In this example, when rows are pinned, they will initially appear to stay in place, but when the user scrolls up or down, the rows will stick to the top or bottom of the table. Learn more about row pinning in the Row Pinning Feature Guide.
Pin | First Name | Last Name | Email | City |
---|---|---|---|---|
Dylan | Murray | dmurray@yopmail.com | East Daphne | |
Raquel | Kohler | rkholer33@yopmail.com | Columbus | |
Ervin | Reinger | ereinger@mailinator.com | South Linda | |
Brittany | McCullough | bmccullough44@mailinator.com | Lincoln | |
Branson | Frami | bframi@yopmain.com | New York | |
Ben | Murray | benm@email.com | Salt Lake City | |
Elena | Smith | esmith@yopmail.com | Los Angeles | |
Michael | Johnson | mjohnson@mailinator.com | Chicago | |
Sophia | Brown | sbrown@yopmail.com | Houston | |
Lucas | Davis | ldavis@mailinator.com | Phoenix | |
Olivia | Garcia | ogarcia@yopmail.com | Philadelphia | |
Liam | Rodriguez | lrodriguez@mailinator.com | San Antonio | |
Emma | Martinez | emartinez@yopmail.com | San Diego | |
Noah | Hernandez | nhernandez@mailinator.com | Dallas | |
Ava | Lopez | alopez@yopmail.com | San Jose | |
William | Gonzalez | wgonzalez@mailinator.com | Austin | |
Isabella | Wilson | iwilson@yopmail.com | Jacksonville | |
James | Anderson | janderson@mailinator.com | Fort Worth | |
Mia | Thomas | mthomas@yopmail.com | Columbus | |
Alexander | Taylor | ataylor@mailinator.com | Charlotte | |
Grace | Moore | gmoore@yopmail.com | Indianapolis | |
Ethan | White | ewhite@mailinator.com | San Francisco | |
Lily | Harris | lharris@yopmail.com | Seattle | |
Daniel | Martin | dmartin@mailinator.com | Denver | |
Zoe | Jackson | zjackson@yopmail.com | Boston | |
Matthew | Thompson | mthompson@mailinator.com | Nashville | |
Ella | Garcia | egarcia@yopmail.com | Detroit | |
David | Martinez | dmartinez@mailinator.com | Portland | |
Aria | Robinson | arobinson@yopmail.com | Las Vegas | |
Joseph | Clark | jclark@mailinator.com | Baltimore |
1import { useMemo } from 'react';2import {3 MaterialReactTable,4 useMaterialReactTable,5 type MRT_ColumnDef,6} from 'material-react-table';7import { data, type Person } from './makeData';89const Example = () => {10 const columns = useMemo<MRT_ColumnDef<Person>[]>(11 () => [12 {13 accessorKey: 'firstName',14 header: 'First Name',15 },16 {17 accessorKey: 'lastName',18 header: 'Last Name',19 },20 {21 accessorKey: 'email',22 header: 'Email',23 },24 {25 accessorKey: 'city',26 header: 'City',27 },28 ],29 [],30 );3132 const table = useMaterialReactTable({33 columns,34 data,35 enableRowPinning: true,36 enablePagination: false,37 enableStickyHeader: true,38 getRowId: (row) => row.email,39 initialState: {40 rowPinning: {41 top: ['rkholer33@yopmail.com', 'egarcia@yopmail.com'],42 bottom: [],43 },44 },45 muiTableContainerProps: {46 sx: {47 maxHeight: '400px',48 },49 },50 muiTableBodyRowProps: ({ row, table }) => {51 const { density } = table.getState();52 return {53 sx: {54 //Set a fixed height for pinned rows55 height: row.getIsPinned()56 ? `${57 //Default mrt row height estimates. Adjust as needed.58 density === 'compact' ? 37 : density === 'comfortable' ? 53 : 6959 }px`60 : undefined,61 },62 };63 },64 });6566 return <MaterialReactTable table={table} />;67};6869export default Example;70
View Extra Storybook Examples