Skip to content

Commit

Permalink
also change table content
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Oct 3, 2024
1 parent f50ba8c commit 4973d27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/react/src/DataTable/DataTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ export const Playground = (args: DataTableProps<UniqueRow> & ColWidthArgTypes) =

const align = args.align as CellAlignment

const [pageIndex, setPageIndex] = React.useState(0)
const start = pageIndex * args.pageSize
const end = start + args.pageSize
const rows = data.slice(start, end)

return (
<Table.Container>
<Table.Title as="h2" id="repositories">
Expand All @@ -207,7 +212,7 @@ export const Playground = (args: DataTableProps<UniqueRow> & ColWidthArgTypes) =
{...args}
aria-labelledby="repositories"
aria-describedby="repositories-subtitle"
data={data}
data={rows}
columns={[
{
header: 'Repository',
Expand Down Expand Up @@ -276,6 +281,15 @@ export const Playground = (args: DataTableProps<UniqueRow> & ColWidthArgTypes) =
},
]}
/>
<Table.Pagination
aria-label="Pagination for Repositories"
pageSize={parseInt(args.pageSize, 10)}
totalCount={data.length}
onChange={({pageIndex}) => {
setPageIndex(pageIndex)
}}
defaultPageIndex={parseInt(args.defaultPageIndex, 10)}
/>
</Table.Container>
)
}
Expand Down Expand Up @@ -318,6 +332,18 @@ Playground.argTypes = {
disable: true,
},
},
pageSize: {
control: {
defaultValue: 5,
type: 'number',
min: 1,
},
},
defaultPageIndex: {
control: {
type: 'number',
},
},
cellPadding: {
control: {
type: 'radio',
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/DataTable/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ function usePagination(config: PaginationConfig): PaginationResult {
if (validDefaultPageCount && defaultIndex !== defaultPageIndex) {
setDefaultIndex(defaultPageIndex)
setPageIndex(defaultPageIndex)
onChange?.({pageIndex: defaultPageIndex})
}
const pageStart = pageIndex * pageSize
const pageEnd = Math.min(pageIndex * pageSize + pageSize, totalCount - 1)
Expand Down

0 comments on commit 4973d27

Please sign in to comment.