mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-Storyless): Add footer support to Table component
This commit is contained in:
@@ -31,6 +31,9 @@ interface TableClassNames {
|
|||||||
tableBodyClassName?: string;
|
tableBodyClassName?: string;
|
||||||
bodyRowClassName?: string;
|
bodyRowClassName?: string;
|
||||||
bodyColumnClassName?: string;
|
bodyColumnClassName?: string;
|
||||||
|
tableFooterClassName?: string;
|
||||||
|
footerRowClassName?: string;
|
||||||
|
footerColumnClassName?: string;
|
||||||
paginationClassName?: string;
|
paginationClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +57,7 @@ export interface TableProps<TData extends object> {
|
|||||||
enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
||||||
renderFooter?: boolean;
|
renderFooter?: boolean;
|
||||||
footerContent?: ReactNode;
|
footerContent?: ReactNode;
|
||||||
|
footerData?: TData[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
|
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
|
||||||
@@ -86,6 +90,9 @@ const Table = <TData extends object>({
|
|||||||
tableBodyClassName: '',
|
tableBodyClassName: '',
|
||||||
bodyRowClassName: '',
|
bodyRowClassName: '',
|
||||||
bodyColumnClassName: '',
|
bodyColumnClassName: '',
|
||||||
|
tableFooterClassName: '',
|
||||||
|
footerRowClassName: '',
|
||||||
|
footerColumnClassName: '',
|
||||||
paginationClassName: '',
|
paginationClassName: '',
|
||||||
},
|
},
|
||||||
emptyContent = emptyContentDefaultValue,
|
emptyContent = emptyContentDefaultValue,
|
||||||
@@ -97,6 +104,7 @@ const Table = <TData extends object>({
|
|||||||
enableRowSelection,
|
enableRowSelection,
|
||||||
renderFooter = false,
|
renderFooter = false,
|
||||||
footerContent,
|
footerContent,
|
||||||
|
footerData = [],
|
||||||
}: TableProps<TData>) => {
|
}: TableProps<TData>) => {
|
||||||
const isServerSideTable =
|
const isServerSideTable =
|
||||||
totalItems !== undefined &&
|
totalItems !== undefined &&
|
||||||
@@ -164,6 +172,14 @@ const Table = <TData extends object>({
|
|||||||
const table = useReactTable(tableOptions);
|
const table = useReactTable(tableOptions);
|
||||||
const { setPageSize } = table;
|
const { setPageSize } = table;
|
||||||
|
|
||||||
|
const footerTableOptions: TableOptions<TData> = {
|
||||||
|
columns,
|
||||||
|
data: footerData,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const footerTable = useReactTable(footerTableOptions);
|
||||||
|
|
||||||
const prevPageClickHandler = () => {
|
const prevPageClickHandler = () => {
|
||||||
table.previousPage();
|
table.previousPage();
|
||||||
|
|
||||||
@@ -266,7 +282,26 @@ const Table = <TData extends object>({
|
|||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
{renderFooter && footerContent}
|
<tfoot className={cn(className.tableFooterClassName)}>
|
||||||
|
{renderFooter &&
|
||||||
|
(footerData && footerData.length > 0
|
||||||
|
? footerTable.getRowModel().rows.map((row) => (
|
||||||
|
<tr key={row.id} className={className.footerRowClassName}>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<td
|
||||||
|
key={cell.id}
|
||||||
|
className={className.footerColumnClassName}
|
||||||
|
>
|
||||||
|
{flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext()
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
: footerContent)}
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user