Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

V8: Is there any simple way to set alignment of column header and body cell? #4439

Discussion options

 const columns: ColumnDef<any,any>[] = [
 {
 accessorKey: "customerName",
 header: "Customer"
 },
 {
 accessorKey: "detail",
 header: "Detail",
 enableSorting: false
 },
 ...

is there any way to make it simple like align: 'center' or className: 'text-center',
which should applies to both header and body cells?

You must be logged in to vote

Done based on this: #4097

fixed with applying below to columnDef:

style: {textAlign: "center"}

and use below to apply style to table header:

style={(header.column.columnDef.meta as any)?.style}

Replies: 3 comments 1 reply

Comment options

Done based on this: #4097

fixed with applying below to columnDef:

style: {textAlign: "center"}

and use below to apply style to table header:

style={(header.column.columnDef.meta as any)?.style}
You must be logged in to vote
1 reply
Comment options

Just in case anyone is interested in "anyless" approach. You could also create *.d.ts file, for example main.d.ts and put it anywhere in your project, for example in the root of your src folder and add the following code there:

import '@tanstack/react-table'
declare module '@tanstack/table-core' {
 interface ColumnMeta<TData extends RowData, TValue> {
 style: {
 textAlign: 'left' | 'center' | 'right'
 }
 }
}

And then header.column.columnDef.meta.style.textAlign will be typed properly.

Tanstack Docs
TypeScript Docs

Answer selected by nimeshvaghasiya
Comment options

why not fix this simple issue?
why extend and declare this simple but make it trivial on the part of the dev?

You must be logged in to vote
0 replies
Comment options

At the risk of being redundant, you can simply define a react component.

This will obviously not apply to both cell & header, but maybe this already helps someone.

E.g. (from original post)

const columns: ColumnDef<any,any>[] = [
 {
 accessorKey: "customerName",
 header: () => <div style={{ textAlign: "right" }}>"Customer"</div>
 },
 {
 accessorKey: "detail",
 header: "Detail",
 enableSorting: false
 },
 ...
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /