Examples › Pinning the first column

Pinning the first column to the left side of the table could be useful when you have a table with many columns and you want to make sure the first column is always visible, even when the table is scrolled horizontally. For instance, you could use this feature to ensure that row actions placed on the first column are always visible.

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 row selection, in which case both the selection checkbox 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 use row 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 are using an absolutely positioned custom title component to create the illusion that the Name text 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...
  />
);

Head over to the next example to discover more features.