diff --git a/packages/canon/src/components/DataTable/DataTable.stories.tsx b/packages/canon/src/components/DataTable/DataTable.stories.tsx index 3119821d92..975a68c165 100644 --- a/packages/canon/src/components/DataTable/DataTable.stories.tsx +++ b/packages/canon/src/components/DataTable/DataTable.stories.tsx @@ -24,6 +24,7 @@ import { getPaginationRowModel, useReactTable, } from '@tanstack/react-table'; +import { useState } from 'react'; const meta = { title: 'Components/DataTable', @@ -32,7 +33,7 @@ const meta = { export default meta; type Story = StoryObj; -export const Default: Story = { +export const Uncontrolled: Story = { render: () => { const table = useReactTable({ data, @@ -96,3 +97,77 @@ export const Default: Story = { ); }, }; + +export const Controlled: Story = { + render: () => { + const [pagination, setPagination] = useState({ + pageIndex: 4, + pageSize: 5, + }); + + const table = useReactTable({ + data, + columns, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + state: { + pagination, + }, + onPaginationChange: setPagination, + }); + + return ( + + + + {table.getHeaderGroups().map(headerGroup => ( + + {headerGroup.headers.map(header => { + return ( + + {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext(), + )} + + ); + })} + + ))} + + + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map(row => ( + + {row.getVisibleCells().map(cell => ( + + {flexRender( + cell.column.columnDef.cell, + cell.getContext(), + )} + + ))} + + )) + ) : ( + + + No results. + + + )} + + + + + ); + }, +}; diff --git a/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx index ef74d12db6..692bd13f76 100644 --- a/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx +++ b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx @@ -45,6 +45,7 @@ const DataTablePagination = forwardRef( size="small" placeholder="Show 10 results" options={[ + { label: 'Show 5 results', value: '5' }, { label: 'Show 10 results', value: '10' }, { label: 'Show 20 results', value: '20' }, { label: 'Show 30 results', value: '30' },