Skip to content

Commit

Permalink
Merge pull request #102 from Kuechlin/fix-auto-reset-pagination-defaults
Browse files Browse the repository at this point in the history
fix: autoResetPageIndex default value
  • Loading branch information
Kuechlin authored Sep 21, 2022
2 parents f3fb786 + 8a8f888 commit eb6125e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
35 changes: 24 additions & 11 deletions docs/pages/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function Demo() {
showEmpty: false,
iconColor: theme.primaryColor,
paginationCompactMode: false,
autoResetPageIndex: true,
});

const onPageChange = (e: DataGridPaginationState) => {
Expand Down Expand Up @@ -152,6 +153,7 @@ export default function Demo() {
highlightOnHover={state.highlightOnHover}
loading={state.loading}
iconColor={state.iconColor}
autoResetPageIndex={state.autoResetPageIndex}
onPageChange={onPageChange}
onSort={onSort}
onFilter={onFilter}
Expand Down Expand Up @@ -350,17 +352,28 @@ export default function Demo() {
})
}
/>
{state.withPagination ? (
<Switch
label="Compact pagination"
checked={state.paginationCompactMode}
onChange={(e) =>
update({
paginationCompactMode: e.target.checked,
})
}
/>
) : null}
{state.withPagination && (
<>
<Switch
label="Compact pagination"
checked={state.paginationCompactMode}
onChange={(e) =>
update({
paginationCompactMode: e.target.checked,
})
}
/>
<Switch
label="Auto reset page index"
checked={state.autoResetPageIndex}
onChange={(e) =>
update({
autoResetPageIndex: e.target.checked,
})
}
/>
</>
)}
<div>
<Text weight="bold">Font Size</Text>
<Slider
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ export default function Properties() {
type: '"default" | "compact"',
description: '"compact" mode will only show pagination step without page size and current page info',
},
{
name: 'autoResetPageIndex',
type: 'boolean',
description:
'If set to false, pagination will NOT be reset to the first page when page-altering state changes eg. data is updated, filters change, grouping changes, etc.',
},
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function DataGrid<TData extends RowData>({
enableRowSelection: !!withRowSelection,
columnResizeMode: 'onChange',
manualPagination: !!total, // when external data, handle pagination manually
autoResetPageIndex: !!autoResetPageIndex,
autoResetPageIndex: autoResetPageIndex,

getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface DataGridProps<TData extends RowData>
paginationMode?: PaginationMode;

/**
* If set to true, pagination will be reset to the first page when page-altering state changes eg. data is updated, filters change, grouping changes, etc.
* If set to false, pagination will NOT be reset to the first page when page-altering state changes eg. data is updated, filters change, grouping changes, etc.
*/
autoResetPageIndex?: boolean;

Expand Down

0 comments on commit eb6125e

Please sign in to comment.