mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
feat(FE): Add renderCustomRow prop to Table
This commit is contained in:
@@ -60,6 +60,12 @@ export interface TableProps<TData extends object> {
|
|||||||
renderFooter?: boolean;
|
renderFooter?: boolean;
|
||||||
withCheckbox?: boolean;
|
withCheckbox?: boolean;
|
||||||
rowOptions?: number[];
|
rowOptions?: number[];
|
||||||
|
/**
|
||||||
|
* Custom row renderer. Should return a complete <tr> element or null.
|
||||||
|
* This gives full control over the row structure including colspan.
|
||||||
|
* Return null to render the default row.
|
||||||
|
*/
|
||||||
|
renderCustomRow?: (row: Row<TData>) => ReactNode | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
|
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
|
||||||
@@ -112,6 +118,7 @@ const Table = <TData extends object>({
|
|||||||
renderFooter = false,
|
renderFooter = false,
|
||||||
withCheckbox = false,
|
withCheckbox = false,
|
||||||
rowOptions = [10, 20, 50, 100],
|
rowOptions = [10, 20, 50, 100],
|
||||||
|
renderCustomRow,
|
||||||
}: TableProps<TData>) => {
|
}: TableProps<TData>) => {
|
||||||
const isServerSideTable =
|
const isServerSideTable =
|
||||||
totalItems !== undefined &&
|
totalItems !== undefined &&
|
||||||
@@ -305,7 +312,14 @@ const Table = <TData extends object>({
|
|||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody className={tableClassNames.tableBodyClassName}>
|
<tbody className={tableClassNames.tableBodyClassName}>
|
||||||
{table.getRowModel().rows.map((row) => (
|
{table.getRowModel().rows.map((row) => {
|
||||||
|
const customRowContent = renderCustomRow?.(row);
|
||||||
|
|
||||||
|
if (customRowContent) {
|
||||||
|
return renderCustomRow?.(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<tr key={row.id} className={tableClassNames.bodyRowClassName}>
|
<tr key={row.id} className={tableClassNames.bodyRowClassName}>
|
||||||
{row.getVisibleCells().map((cell) => (
|
{row.getVisibleCells().map((cell) => (
|
||||||
<td
|
<td
|
||||||
@@ -316,13 +330,17 @@ const Table = <TData extends object>({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{!isLoading &&
|
{!isLoading &&
|
||||||
flexRender(cell.column.columnDef.cell, cell.getContext())}
|
flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext()
|
||||||
|
)}
|
||||||
|
|
||||||
{isLoading && <div className='skeleton w-full h-4' />}
|
{isLoading && <div className='skeleton w-full h-4' />}
|
||||||
</td>
|
</td>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot className={cn(tableClassNames.tableFooterClassName)}>
|
<tfoot className={cn(tableClassNames.tableFooterClassName)}>
|
||||||
{renderFooter && (
|
{renderFooter && (
|
||||||
|
|||||||
Reference in New Issue
Block a user