Sticky Row Selection Example
Material React Table has the ability to pin rows as they are selected and keep them in view while scrolling. In this example, when rows are selected, they will initially appear to stay in place, but when the user scrolls up or down, the selected rows will stick to the top or bottom of the table. Learn more about row pinning in the Row Pinning Feature Guide.
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 //column definitions...32 );3334 const table = useMaterialReactTable({35 columns,36 data,37 enablePagination: false,38 enableRowPinning: true,39 enableRowSelection: true,40 enableStickyHeader: true,41 rowPinningDisplayMode: 'select-sticky',42 getRowId: (row) => row.email,43 initialState: {44 rowPinning: {45 top: ['ereinger@mailinator.com'],46 },47 rowSelection: {48 'ereinger@mailinator.com': true,49 },50 },51 muiTableContainerProps: {52 sx: {53 maxHeight: '400px',54 },55 },56 muiTableBodyRowProps: ({ row, table }) => {57 const { density } = table.getState();58 return {59 sx: {60 //Set a fixed height for pinned rows61 height: row.getIsPinned()62 ? `${63 //Default mrt row height estimates. Adjust as needed.64 density === 'compact' ? 37 : density === 'comfortable' ? 53 : 6965 }px`66 : undefined,67 },68 };69 },70 });7172 return <MaterialReactTable table={table} />;73};7475export default Example;76
View Extra Storybook Examples