Skip to content

How to add a custom class to a specific column header <th> tag? #4824

Discussion options

You must be logged in to vote

You can add a property for the class name into column meta.

declare module "@tanstack/table-core" {
  interface ColumnMeta<TData extends RowData, TValue> {
    className?: string;
  }
}

Then, you can define a className for the column that you want:

columnHelper.accessor("options", {
  cell: // your implementation,
  header: // your implementation,
  footer: // your implementation,
  meta: {
    className: "classname-for-the-options-column",
  },
}),

Then, you can get it through the column.columnDef.meta?.className.

// I do not know vue, it is for react, but you can got the idea.
<th className={column.columnDef.meta?.className ?? ""}> // also for <td>

Hope it is useful.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@richcoleman-alphatrust
Comment options

@marioteik
Comment options

Answer selected by richcoleman-alphatrust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants