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 OptionTypeDescription
accessorFnAccessorFn<TData>The resolved accessor function to use when extracting the value for the column from each row.
clearSorting() => voidRemoves this column from the table's sorting state.
columnDefColumnDef<TData>The original column def used to create the column.
columnsST_ColumnDef<TData>[]The child column (if the column is a group column).
depthnumberThe depth of the column (if grouped) relative to the root column def array.
getAfter
getAggregationFns() => Array<AggregationFnDef> | undefinedReturns the aggregation function definitions (either user-defined or automatic, depending on configuration).
getAutoAggregationFn
getAutoFilterFn
getAutoSortDir
getAutoSortFn
getCanFilter
getCanGlobalFilter
getCanGroup
getCanHide
getCanMultiSort
getCanPin
getCanResize
getCanSort
getFacetedMinMaxValues
getFacetedRowModel
getFacetedUniqueValues
getFilterFn
getFilterIndex
getFilterValue
getFirstSortDir
getFlatColumns
getGroupedIndex
getIndex
getIsFiltered
getIsFirstColumn
getIsGrouped
getIsLastColumn
getIsPinned
getIsResizing
getIsSorted
getIsVisible
getLeafColumns
getNextSortingOrder
getPinnedIndex
getSize
getSortFn
getSortIndex
getStart
getToggleGroupingHandler
getToggleSortingHandler
getToggleVisibilityHandler
id
parent
pin
resetSize
setFilterValue
toggleGrouping
toggleSorting
toggleVisibility

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