[v8] How to add custom class to a cell in the column definition #5319
-
I'm trying to add a class from the Column definition to the element. Like the following const defaultColumns: ColumnDef<Person>[] = [
{
accessorKey: 'firstName',
cell: info => info.getValue(),
footer: info => info.column.id,
myCustomClassList: ["d-flex"] // custom class only to this column
}]
<For each={row.getVisibleCells()}>
{cell => (
<td class={...cell.myCustomClass()}> // Add class here
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</td>
)}
</For> I was browsing and I found this issue that explains that previewsly, a className property could be provided but now in version 7 its done through custom props using cell.getCellProps, and it redirects me to this issue that has this working example. But it did not work in version 8. Reading the documentation for migration to v8, it says that this option was deprecated, but it does not give any replacement. It uses flexRender but only inside the element, so it does not expose any properties to the td but the id. I know that I can change my render funcion and start the rendering outside the like the following: const defaultColumns: ColumnDef<Person>[] = [
{
accessorKey: 'firstName',
cell: info => <td class="d-flex">{info.getValue()}<td>,
footer: info => info.column.id
}]
<For each={row.getVisibleCells()}>
{cell => (
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
)}
</For> But this would require me to manually add the element to each column even when 90% of the time I dont need to add a custom class. I think I am missing something from the v8 docuentantion hopefully simple. Any help is greatly appreciated. Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
cell.column.columnDef.myCustomClassList |
Beta Was this translation helpful? Give feedback.
-
I still cant apply custom class to my Header or Cell. There is my code: https://pastebin.com/Md3X16hH I just want to "text-right" my Amount column and cell.
How to do it? |
Beta Was this translation helpful? Give feedback.
I don't use typescript thankgoodness :), I know the "official" way is to do cell.column.columnDef.meta.myCustomClassList, not sure if that fixes typescript issue or not because I've never used it.
{
accessorKey: 'firstName',
cell: info => info.getValue(),
footer: info => info.column.id,
meta: {myCustomClassList ["d-flex"] }
}]