Row grouping in data-table #2809
-
Hello guys. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi @JuanPedroPontVerges, to be honest, I've never used an expandable line, but to give you a way to solve this, maybe you could use an accordion component on the row. I just don't know how you can put other lines inside the accordion, but maybe this is a good way to go. |
Beta Was this translation helpful? Give feedback.
-
So i've figured out a way to have a collapse in a row. <TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<Collapsible key={row.id} asChild>
<>
<CollapsibleTrigger asChild>
<TableRow data-state={row.getIsSelected() && "selected"} className="!appearance-none">
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
</CollapsibleTrigger>
<CollapsibleContent asChild>
<ExpandedContent dollars={[]} />
</CollapsibleContent>
</>
</Collapsible>
))
) : (
<TableRow>
<TableCell colSpan={columns.length} className="h-24 text-left sm:text-center">
Sin resultados.
</TableCell>
</TableRow>
)}
</TableBody> And this is how the ExpandedContent component looks like: const ExpandedContent: React.FC<ExpandedContentType> = ({ dollars }) => {
return (
<>
<TableRow>
<TableCell>{1}</TableCell>
<TableCell>{2}</TableCell>
<TableCell>Holis!!</TableCell>
</TableRow>
<TableRow>
<TableCell>{1}</TableCell>
<TableCell>{2}</TableCell>
<TableCell>Holis!!</TableCell>
</TableRow>
<TableRow>
<TableCell>{1}</TableCell>
<TableCell>{2}</TableCell>
<TableCell>Holis!!</TableCell>
</TableRow>
</>
);
};
export default ExpandedContent; And you end up having something like this: |
Beta Was this translation helpful? Give feedback.
-
hi do you know How to allow only one row to be open at a time? |
Beta Was this translation helpful? Give feedback.
So i've figured out a way to have a collapse in a row.