Skip to content

Commit

Permalink
Page reset examples
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh committed Feb 4, 2025
1 parent 875845f commit 20ffdf4
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/data/data-grid/filtering/FilteringWithPageReset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { DataGrid, GridToolbar } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function FilteringWithPageReset() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
loading={loading}
pagination
initialState={{ pagination: { paginationModel: { page: 0, pageSize: 10 } } }}
pageSizeOptions={[10]}
resetPageAfterSortingOrFiltering
slots={{ toolbar: GridToolbar }}
/>
</div>
);
}
27 changes: 27 additions & 0 deletions docs/data/data-grid/filtering/FilteringWithPageReset.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { DataGrid, GridToolbar } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function FilteringWithPageReset() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
loading={loading}
pagination
initialState={{ pagination: { paginationModel: { page: 0, pageSize: 10 } } }}
pageSizeOptions={[10]}
resetPageAfterSortingOrFiltering
slots={{ toolbar: GridToolbar }}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<DataGrid
{...data}
loading={loading}
pagination
initialState={{ pagination: { paginationModel: { page: 0, pageSize: 10 } } }}
pageSizeOptions={[10]}
resetPageAfterSortingOrFiltering
slots={{ toolbar: GridToolbar }}
/>
6 changes: 6 additions & 0 deletions docs/data/data-grid/filtering/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ const columns = [

{{"demo": "ReadOnlyFilters.js", "bg": "inline", "defaultCodeOpen": false}}

## Reset pagination

By default user stays on the same page after the filter is applied, unless the new row count indicates that that page does not exist anymore. In that case, page is changed to the last page for the new row count. If you want to get the user back to the first page each time new filter is applied, use `resetPageAfterSortingOrFiltering` prop.

{{"demo": "FilteringWithPageReset.js", "bg": "inline", "defaultCodeOpen": false}}

## Ignore diacritics (accents)

You can ignore diacritics (accents) when filtering the rows. See [Quick filter - Ignore diacritics (accents)](/x/react-data-grid/filtering/quick-filter/#ignore-diacritics-accents).
Expand Down
26 changes: 26 additions & 0 deletions docs/data/data-grid/sorting/SortingWithPageReset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function SortingWithPageReset() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
loading={loading}
pagination
pageSizeOptions={[10]}
initialState={{ pagination: { paginationModel: { page: 0, pageSize: 10 } } }}
resetPageAfterSortingOrFiltering
/>
</div>
);
}
26 changes: 26 additions & 0 deletions docs/data/data-grid/sorting/SortingWithPageReset.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function SortingWithPageReset() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
loading={loading}
pagination
pageSizeOptions={[10]}
initialState={{ pagination: { paginationModel: { page: 0, pageSize: 10 } } }}
resetPageAfterSortingOrFiltering
/>
</div>
);
}
8 changes: 8 additions & 0 deletions docs/data/data-grid/sorting/SortingWithPageReset.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<DataGrid
{...data}
loading={loading}
pagination
pageSizeOptions={[10]}
initialState={{ pagination: { paginationModel: { page: 0, pageSize: 10 } } }}
resetPageAfterSortingOrFiltering
/>
6 changes: 6 additions & 0 deletions docs/data/data-grid/sorting/sorting.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ In the following demo, the `firstName` column is not sortable by the default gri

{{"demo": "ReadOnlySortingGrid.js", "bg": "inline", "defaultCodeOpen": false}}

## Reset pagination

By default sorting does not change the current page. If you want to get the user back to the first page each time new sort is applied, use `resetPageAfterSortingOrFiltering` prop.

{{"demo": "SortingWithPageReset.js", "bg": "inline", "defaultCodeOpen": false}}

## Custom comparator

A comparator determines how two cell values should be sorted.
Expand Down

0 comments on commit 20ffdf4

Please sign in to comment.