Examples › Pinning the first column

When a table has many columns and needs to scroll horizontally, you may want to make sure its first column is always visible — for instance, to keep the record name or the row actions in view at all times.

You can achieve this by setting the pinFirstColumn DataTable prop to true:

First name
Last name
Department
Company
City
State
Address
Mission statement
JeraldHowellIndustrialRunte IncMcAllenMA2996 Ronny MountEngage synergistic infrastructures.
KathleenRueckerComputersShanahan, Robel and BeierWest GerryKS378 Berta CrescentSynthesize customized portals.
EricaVolkmanToysGoyette IncDorthysideID8873 Mertz RapidProductize front-end web services.
CliffordOberbrunnerAutomotiveRau - O'HaraShieldsboroughMI7508 Lansdowne RoadInnovate real-time applications.
AlisonKlingJeweleryGoyette IncDorthysideID8873 Mertz RapidProductize front-end web services.
No records

Here is the code:

return (
  <DataTable
    pinFirstColumn // 👈 make sure the first column is always visible
    // other table props...
  />
);

You can also combine this feature with records selection, in which case both the selection checkbox column and the first user-provided column will be pinned to the left side of the table:

First name
Last name
Department
Company
City
State
Address
Mission statement
JeraldHowellIndustrialRunte IncMcAllenMA2996 Ronny MountEngage synergistic infrastructures.
KathleenRueckerComputersShanahan, Robel and BeierWest GerryKS378 Berta CrescentSynthesize customized portals.
EricaVolkmanToysGoyette IncDorthysideID8873 Mertz RapidProductize front-end web services.
CliffordOberbrunnerAutomotiveRau - O'HaraShieldsboroughMI7508 Lansdowne RoadInnovate real-time applications.
AlisonKlingJeweleryGoyette IncDorthysideID8873 Mertz RapidProductize front-end web services.
No records

Here is the code:

return (
  <DataTable
    pinFirstColumn // 👈 make sure the first column is always visible
    selectedRecords={selectedRecord}
    onSelectedRecordsChange={setSelectedRecord}
    // other table props...
  />
);

You can also use records selection and pin both the first and the last column at the same time:

First name
Last name
Department
Company
City
State
Address
Mission statement
JeraldHowellIndustrialRunte IncMcAllenMA2996 Ronny MountEngage synergistic infrastructures.
KathleenRueckerComputersShanahan, Robel and BeierWest GerryKS378 Berta CrescentSynthesize customized portals.
EricaVolkmanToysGoyette IncDorthysideID8873 Mertz RapidProductize front-end web services.
CliffordOberbrunnerAutomotiveRau - O'HaraShieldsboroughMI7508 Lansdowne RoadInnovate real-time applications.
AlisonKlingJeweleryGoyette IncDorthysideID8873 Mertz RapidProductize front-end web services.
No records

Here is the code:

return (
  <DataTable
    pinFirstColumn // 👈 make sure the first column is always visible
    pinLastColumn // 👈 make sure the last column is always visible
    selectedRecords={selectedRecord}
    onSelectedRecordsChange={setSelectedRecord}
    // other table props...
  />
);

Using with column grouping

Here is an example of how you can pin the first column when using column grouping. Notice how the first group contains only one column, and how we’re using an absolutely positioned custom title component to create the illusion that the Name title is centered vertically:

Workplace informationWorkplace location

Name

Company
Department
Mission statement
City
State
Address

Actions

Jerald HowellRunte IncIndustrialEngage synergistic infrastructures.McAllenMA2996 Ronny Mount
Kathleen RueckerShanahan, Robel and BeierComputersSynthesize customized portals.West GerryKS378 Berta Crescent
Erica VolkmanGoyette IncToysProductize front-end web services.DorthysideID8873 Mertz Rapid
Clifford OberbrunnerRau - O'HaraAutomotiveInnovate real-time applications.ShieldsboroughMI7508 Lansdowne Road
Alison KlingGoyette IncJeweleryProductize front-end web services.DorthysideID8873 Mertz Rapid
No records

Here is the code:

return (
  <DataTable
    withTableBorder
    withColumnBorders
    pinFirstColumn
    pinLastColumn
    groups={[
      {
        id: 'name',
        title: '', // 👈 empty title
        style: { borderBottomColor: 'transparent' }, // 👈 hide the bottom border
        columns: [
          {
            accessor: 'name',
            title: (
              // 👇 use an absolutely positioned custom title component
              //    to center the title vertically
              <Text inherit pos="absolute" mt={-28}>
                Name
              </Text>
            ),
            noWrap: true,
            render: ({ firstName, lastName }) => `${firstName} ${lastName}`,
          },
        ],
      },
      // other column groups...
      },
    ]}
    // other table props...
  />
);

Mantine DataTable is used and trusted by