Examples › Pinning the last column

You may have noticed that when you are using row selection and the table needs to scroll horizontally, the checkbox column is always visible. This is because the checkbox column is pinned to the left side of the table.

In the same way, pinning the last column to the right side of the table could be useful when you have a table with many columns and you want to make sure the last column is always visible, even when the table is scrolled horizontally. For instance, you could use this feature to ensure that the row actions are always visible.

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

First name
Last name
Department
Company
City
State
Address
Mission statement
Row actions
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
    pinLastColumn // 👈 make sure the last column is always visible
    // other table props...
  />
);

Using with column grouping

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

NameWorkplace informationWorkplace location
First name
Last name
Company
Department
Mission statement
City
State
Address

Actions

JeraldHowellRunte IncIndustrialEngage synergistic infrastructures.McAllenMA2996 Ronny Mount
KathleenRueckerShanahan, Robel and BeierComputersSynthesize customized portals.West GerryKS378 Berta Crescent
EricaVolkmanGoyette IncToysProductize front-end web services.DorthysideID8873 Mertz Rapid
CliffordOberbrunnerRau - O'HaraAutomotiveInnovate real-time applications.ShieldsboroughMI7508 Lansdowne Road
AlisonKlingGoyette IncJeweleryProductize front-end web services.DorthysideID8873 Mertz Rapid
No records

Here is the code:

return (
  <DataTable
    withTableBorder
    withColumnBorders
    pinLastColumn
    groups={[
      // other column groups...
      // 👇 this group has only one column, so it will be pinned to the right side of the table
      {
        id: 'actions',
        title: '', // 👈 empty title
        style: { borderBottomColor: 'transparent' }, // 👈 hide the group bottom border
        columns: [
          {
            accessor: 'actions',
            title: (
              // 👇 use an absolutely positioned custom title component
              //    to center the title vertically
              <Text inherit pos="absolute" mt={-28} ml={12}>
                Actions
              </Text>
            ),
            render: (employee) => (
              <Group gap={4} wrap="nowrap">
                <ActionIcon
                  size="sm"
                  variant="subtle"
                  color="green"
                  onClick={() => showModal({ employee, action: 'view' })}
                >
                  <IconEye size={16} />
                </ActionIcon>
                <ActionIcon
                  size="sm"
                  variant="subtle"
                  color="blue"
                  onClick={() => showModal({ employee, action: 'edit' })}
                >
                  <IconEdit size={16} />
                </ActionIcon>
                <ActionIcon
                  size="sm"
                  variant="subtle"
                  color="red"
                  onClick={() => showModal({ employee, action: 'delete' })}
                >
                  <IconTrash size={16} />
                </ActionIcon>
              </Group>
            ),
          },
        ],
      },
    ]}
    // other table props...
  />
);

Head over to the next example to discover how you can pin the first column to the left side of the table.