DocsAPI Reference

API Reference

Column Instance APIs

All the column instance methods and objects that can be accessed from a column instance in Shadcn Table

NOTE: These are NOT column options for Shadcn Table. These are just static methods on a column instance that you can use.

Each column has a column instance object associated with it that can be accessed in callback props and other places in the table.

You can access and use a column instance in quite a few places, but here are some of the most common:

const columns = [
  {
    accessorKey: 'username',
    header: 'Username',
    //you can access a column instance in many callback functions in a column definition like this
    stTableHeadCellProps: ({ column }) => ({
      style: {
        color: column.getIsSorted() ? 'red' : 'black',
      },
    }),
    //or in the component override callbacks
    Header: ({ column }) => <div>{column.columnDef.header}</div>,
    Cell: ({ cell, column }) => (
      <span
        style={{
          backgroundColor: column.getIsGrouped() ? 'green' : 'white',
        }}
      >
        {cell.getValue()}
      </span>
    ),
  },
];

const table = useShadcnTable({
  columns,
  data,
  //or in callback props like this
  stTableBodyCellProps: ({ column }) => ({
    style: {
      boxShadow: column.getIsPinned() ? '0 0 0 2px red' : 'none',
    },
  }),
});
#
State Option
Type
More Info Links
1AccessorFn<TData>TanStack Table Column API Docs
2() => voidTanStack Table Sorting API Docs
3ColumnDef<TData>TanStack Table Column API Docs
4ST_ColumnDef<TData>[]TanStack Table Column API Docs
5numberTanStack Table Column API Docs
6
7() => Array<AggregationFnDef> | undefinedTanStack Table Grouping Docs
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

Wanna see the source code for this table? Check it out down below!