DocsGuides

Guides

Display (Built-in) Columns

How to create or edit display columns in Shadcn Table

Display columns are used to display non-data elements in a table. They only require an id and header in the column definition. They do not need an accessorKey or accessorFn, as they are not meant to connect to your data at all.

Example

Display columns do not have any processing features, such as sorting, filtering, grouping, etc. enabled on them by default.

Relevant Table Options

Prop NameTypeDescription
defaultDisplayColumnPartial<ST_DisplayColumnDef<TData>>Default column options to use for all display column defs supplied to the table. This is useful for providing default cell/header/footer renderers, or turning on or off certain features for all display columns.
displayColumnDefOptions{ [key: string]: ST_DisplayColumnDef<TData> }Customize and override the column definition options for the built-in display columns. (Select, Expand, Row Actions, etc.)

Built-in ST Display Columns

Shadcn Table has a few built-in display columns that are created automatically when certain features are enabled.

  • st-row-pin - created when enableRowPinning table option is true with certain rowPinningDisplayMode values
  • st-row-drag - created when enableRowDragging or enableRowOrdering table option are true
  • st-row-actions - created when enableRowActions (or sometimes when enableEditing) props are true
  • st-row-expand - created when enableExpanding, enableGrouping, or renderDetailPanel props are true
  • st-row-select - created when enableRowSelection table option is true
  • st-row-numbers - created when enableRowNumbers table option is true
  • st-row-spacer - created only when you set layoutMode: "grid-no-grow" yourself; the default "grid" layout has no spacer column

The row actions column sits last by default, 48 px wide and pinned to the end so it stays visible while the table scrolls sideways; its header label is for screen readers only. See the Row Actions Guide to put it first. Display columns have grow: false by default, so in the default "grid" layout they keep their set width while the data columns share the spare width. Every built-in display column except row actions is locked while another column is dragged (see Locked Columns).

Display columns are, for the most part, the same as a data column, except they do not have an accessor to access data. When a display column is created internally by Shadcn Table, the following options are all set to false by default:

const defaultDisplayColumnDefOptions = {
  columnDefType: 'display',
  enableClickToCopy: false,
  enableColumnActions: false,
  enableColumnDragging: false,
  enableColumnFilter: false,
  enableColumnOrdering: false,
  enableEditing: false,
  enableGlobalFilter: false,
  enableGrouping: false,
  enableHiding: false,
  enableResizing: false,
  enableSorting: false,
} as Partial<ST_ColumnDef>;

All of these values are able to be overridden if needed, and you'll learn about that in the next section down below.

Customize Built-in ST Display Columns

It is possible to change and override the default behavior of built-in display columns. Whether you want to change the default column width, add some styles, or enable some features, such as column actions or column drag and drop, you can do it with the displayColumnDefOptions table option.

Default Display Column Table Option

First of all, if you want to enable or disable some feature for all display columns, you can just use the defaultDisplayColumn table option. This will apply to all display columns, including any custom display columns you create.

const table = useShadcnTable({
  columns,
  data,
  defaultDisplayColumn: {
    enableColumnOrdering: true,
    enableColumnResizing: true,
    minSize: 100,
  },
});

Display Column Definition Options Table Option

Let's say you need to adjust the width of the Actions column to be wide enough to fit all of your action buttons. You could do that as follows:

const table = useShadcnTable({
  columns,
  data,
  displayColumnDefOptions: { 'st-row-actions': { size: 300 } }, //change width of actions column to 300px
  enableRowActions: true,
  renderRowActions: ({ row }) => (
    <span>
      <Button>Action 1</Button>
      <Button>Action 2</Button>
      <Button>Action 3</Button>
    </span>
  ),
});

return <ShadcnTable table={table} />;

Or maybe you want to enable a feature that is off by default for display columns, such as column ordering or pinning.

const table = useShadcnTable({
  columns,
  data,
  displayColumnDefOptions: {
    'st-row-numbers': {
      enableColumnOrdering: true, //no longer locked: it can be dragged and takes drops
      enablePinning: true,
      enableColumnActions: true,
      size: 40,
    },
  },
  enableRowNumbers: true,
});

return <ShadcnTable table={table} />;

Here is a full example and demo for customizing display columns.

Storybook

Create your own Display Columns

You do not have to use the built in Row Actions feature. You can just create your own display columns instead. It is as easy as creating a normal column, only specifying the columnDefType as display.

const columns = [
  {
    id: 'sendEmail',
    header: 'Send Email',
    columnDefType: 'display', //turns off data column features like sorting, filtering, etc.
    enableColumnOrdering: true, //but you can turn back any of those features on if you want like this
    Cell: ({ row }) => (
      <Button onClick={() => sendEmail(row.original.userId)}>Send Email</Button>
    ),
  },
  {
    id: 'name',
    header: 'Name',
    accessorKey: 'name',
  },
];

On this page