T
TanStack3y ago
absent-sapphire

Combine columns into single column

Is it possible to achieve the following CSS layout using TanStack tables? In particular, I'm referring to the song artists being listed underneath the song title like in the included screenshot. In my data, the format is an object as follows:
[
{
id: number;
title: string;
composers: [...{}];
...
},
...
]
[
{
id: number;
title: string;
composers: [...{}];
...
},
...
]
No description
5 Replies
other-emerald
other-emerald3y ago
For that particular column alone, you could render custom cells using your ColumnDefs
other-emerald
other-emerald3y ago
ColumnDef | TanStack Table Docs
Column definitions are plain objects with the following options: Options
other-emerald
other-emerald3y ago
Inside, the render method, you can get access to the full row details, and then display it in a component accordingly. I've done something similar below. https://github.com/SeanCassiere/nv-rental-clone/blob/master/src/pages/AgreementsSearch/AgreementsSearchPage.tsx#L84-L109
GitHub
nv-rental-clone/AgreementsSearchPage.tsx at master · SeanCassiere/n...
Navotar with Tailwind and the Tanstack. Contribute to SeanCassiere/nv-rental-clone development by creating an account on GitHub.
united-yellow
united-yellow2y ago
Is there any way to combine real columns? The above works fine is most cases, but you lose sorting and filtering on those values
other-emerald
other-emerald2y ago
You could use the accessorFn to combine the column values into a single value (without doing the combing in JSX) and then your filters would then be run on that returned value. https://tanstack.com/table/v8/docs/guide/column-defs#accessor-functions

Did you find this page helpful?