-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGrid] Allow to ignore diacritics when filtering (#10569)
- Loading branch information
1 parent
9ba8e44
commit b0cb729
Showing
30 changed files
with
370 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, GridToolbar } from '@mui/x-data-grid'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Switch from '@mui/material/Switch'; | ||
|
||
const dateFormatter = new Intl.DateTimeFormat('fr-FR', { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
}); | ||
|
||
const rows = [ | ||
{ id: 0, string: 'Café', date: new Date(2023, 1, 1), singleSelect: 'Jalapeño' }, | ||
]; | ||
|
||
const columns = [ | ||
{ field: 'string', width: 100 }, | ||
{ | ||
field: 'date', | ||
type: 'date', | ||
width: 150, | ||
valueFormatter: (params) => dateFormatter.format(params.value), | ||
}, | ||
{ | ||
field: 'singleSelect', | ||
type: 'singleSelect', | ||
valueOptions: ['Jalapeño'], | ||
}, | ||
]; | ||
|
||
export default function QuickFilteringDiacritics() { | ||
const [filterModel, setFilterModel] = React.useState({ | ||
items: [], | ||
quickFilterValues: ['cafe'], | ||
}); | ||
const [ignoreDiacritics, setIgnoreDiacritics] = React.useState(true); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<FormControlLabel | ||
checked={ignoreDiacritics} | ||
onChange={(event) => setIgnoreDiacritics(event.target.checked)} | ||
control={<Switch />} | ||
label="Ignore diacritics" | ||
/> | ||
<div style={{ height: 200, width: '100%' }}> | ||
<DataGrid | ||
key={ignoreDiacritics.toString()} | ||
rows={rows} | ||
columns={columns} | ||
filterModel={filterModel} | ||
onFilterModelChange={setFilterModel} | ||
disableColumnSelector | ||
disableDensitySelector | ||
hideFooter | ||
slots={{ toolbar: GridToolbar }} | ||
slotProps={{ toolbar: { showQuickFilter: true } }} | ||
ignoreDiacritics={ignoreDiacritics} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<DataGrid rows={[{ id: 0, value: 'Café' }]} columns={columns} /> |
69 changes: 69 additions & 0 deletions
69
docs/data/data-grid/filtering/QuickFilteringDiacritics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react'; | ||
import { | ||
DataGrid, | ||
GridToolbar, | ||
GridColDef, | ||
GridFilterModel, | ||
} from '@mui/x-data-grid'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Switch from '@mui/material/Switch'; | ||
|
||
const dateFormatter = new Intl.DateTimeFormat('fr-FR', { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
}); | ||
|
||
const rows = [ | ||
{ id: 0, string: 'Café', date: new Date(2023, 1, 1), singleSelect: 'Jalapeño' }, | ||
]; | ||
const columns: GridColDef[] = [ | ||
{ field: 'string', width: 100 }, | ||
{ | ||
field: 'date', | ||
type: 'date', | ||
width: 150, | ||
valueFormatter: (params) => dateFormatter.format(params.value), | ||
}, | ||
{ | ||
field: 'singleSelect', | ||
type: 'singleSelect', | ||
valueOptions: ['Jalapeño'], | ||
}, | ||
]; | ||
|
||
export default function QuickFilteringDiacritics() { | ||
const [filterModel, setFilterModel] = React.useState<GridFilterModel>({ | ||
items: [], | ||
quickFilterValues: ['cafe'], | ||
}); | ||
const [ignoreDiacritics, setIgnoreDiacritics] = React.useState(true); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<FormControlLabel | ||
checked={ignoreDiacritics} | ||
onChange={(event) => | ||
setIgnoreDiacritics((event.target as HTMLInputElement).checked) | ||
} | ||
control={<Switch />} | ||
label="Ignore diacritics" | ||
/> | ||
<div style={{ height: 200, width: '100%' }}> | ||
<DataGrid | ||
key={ignoreDiacritics.toString()} | ||
rows={rows} | ||
columns={columns} | ||
filterModel={filterModel} | ||
onFilterModelChange={setFilterModel} | ||
disableColumnSelector | ||
disableDensitySelector | ||
hideFooter | ||
slots={{ toolbar: GridToolbar }} | ||
slotProps={{ toolbar: { showQuickFilter: true } }} | ||
ignoreDiacritics={ignoreDiacritics} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.