Reputation: 13
I am migrating from React table V6 to @tanstack/react-table V8. I am able to migrate the basic functionality like sorting, filtering and column resizing etc.
Previously I was using "react-table-hoc-fixed-columns"(https://www.npmjs.com/package/react-table-hoc-fixed-columns) to fix certain columns.
I have spent large chunk of my time going through source code. Here are my findings:
If someone encountered this problem or have any advice how can I make it work in @tanstack/react-table v8.
Upvotes: 1
Views: 9689
Reputation: 21
You can add sticky properties for a column in the className into column meta.
import "@tanstack/react-table";
import { RowData } from "@tanstack/react-table";
declare module "@tanstack/react-table" {
interface ColumnMeta<TData extends RowData, TValue> {
className: string;
}
}
const columns = [
{
header: "Sticky Column",
accessorKey: "stickyColumn",
meta: {
className:
"sticky right-0",
},
},
// other columns
]
//Then, you can get it through the column.columnDef.meta?.className. Add the className in th and td tag.
<th
className={`${
header.column.columnDef.meta?.className ?? ""
}
// other tailwind CSS properties
`}
key={header.id}
colSpan={header.colSpan}
>
<td
key={cell.id}
className={`${
cell.column.columnDef.meta?.className ?? ""
}
// other tailwind CSS properties
`}
>
Upvotes: 2