Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Add quick filtering engine #4317

Merged
merged 49 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7f3e501
aff quick filter logic
alexfauquette Mar 30, 2022
6306109
add the component
alexfauquette Mar 30, 2022
f9f1276
update defautl col def
alexfauquette Mar 30, 2022
2fb5288
fixes
alexfauquette Mar 30, 2022
1f5e6bf
documentation
alexfauquette Mar 30, 2022
d632bd6
support row grouping filter
alexfauquette Mar 31, 2022
3d91292
run scripts
alexfauquette Mar 31, 2022
b10e885
fix typescript
alexfauquette Mar 31, 2022
18a3783
fix proptypes
alexfauquette Mar 31, 2022
38af3ad
yarn docs:api
alexfauquette Mar 31, 2022
f71e1a6
smaal fixes
alexfauquette Apr 1, 2022
eb02b14
flaviens idea to keep hook code clean
alexfauquette Apr 1, 2022
b22e58b
remove useless type
alexfauquette Apr 1, 2022
18ee00f
support single select
alexfauquette Apr 5, 2022
bad0fd9
add labels
alexfauquette Apr 5, 2022
b807e99
script
alexfauquette Apr 5, 2022
5d14e6a
add tests
alexfauquette Apr 6, 2022
2f9ebb9
debounce the quick filter input
alexfauquette Apr 6, 2022
62362df
scripts
alexfauquette Apr 6, 2022
48e1272
feedbacks
alexfauquette Apr 6, 2022
5638410
stop exporting removed type
alexfauquette Apr 6, 2022
663af5a
typo fixes
alexfauquette Apr 6, 2022
4178ba3
l10n
alexfauquette Apr 7, 2022
6c39cfd
Merge remote-tracking branch 'upstream/master' into quick-filter
alexfauquette Apr 14, 2022
cea2351
work
alexfauquette Apr 14, 2022
6b7f70c
fix tests
alexfauquette Apr 14, 2022
2e7546f
naming and desctiption feedbacks
alexfauquette Apr 14, 2022
9d3e500
type="search" add the clear icon automatically
alexfauquette Apr 14, 2022
0f71f3b
add property descriptions
alexfauquette Apr 14, 2022
4511f4b
add quick fiolter in the default toolbar
alexfauquette Apr 14, 2022
ab7e6d3
wordings
alexfauquette Apr 14, 2022
5ee9952
fix single select when value is an object
alexfauquette Apr 14, 2022
a267eff
scripts
alexfauquette Apr 14, 2022
9a3c346
proptypes
alexfauquette Apr 14, 2022
18bca76
fixes
alexfauquette Apr 19, 2022
8caecfd
JOse feedbacks
alexfauquette Apr 22, 2022
90ec3eb
Update docs/data/data-grid/filtering/filtering.md
alexfauquette Apr 22, 2022
bfbfddf
Update docs/data/data-grid/filtering/filtering.md
alexfauquette Apr 22, 2022
4271fb6
feedbacks
alexfauquette Apr 28, 2022
e273095
prettier
alexfauquette Apr 28, 2022
ad137fa
Merge remote-tracking branch 'upstream/master' into quick-filter
alexfauquette Apr 28, 2022
85700fd
Merge remote-tracking branch 'upstream/master' into quick-filter
alexfauquette May 2, 2022
c5efa4f
Mat feedbacks
alexfauquette May 3, 2022
9cca6c9
Merge remote-tracking branch 'upstream/master' into quick-filter
alexfauquette May 3, 2022
77a970e
Merge remote-tracking branch 'upstream/master' into quick-filter
alexfauquette May 6, 2022
63954a9
CSS fixes
alexfauquette May 6, 2022
39c3ade
add quick filter to demos
alexfauquette May 6, 2022
321e4a0
fix demo
alexfauquette May 9, 2022
754022a
Merge remote-tracking branch 'upstream/master' into quick-filter
alexfauquette May 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/data/data-grid/demo/FullFeaturedDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ export default function FullFeaturedDemo() {
components={{
Toolbar: GridToolbar,
}}
componentsProps={{
toolbar: { showQuickFilter: true },
}}
loading={loading}
checkboxSelection
disableSelectionOnClick
Expand Down
3 changes: 3 additions & 0 deletions docs/data/data-grid/demo/FullFeaturedDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ export default function FullFeaturedDemo() {
components={{
Toolbar: GridToolbar,
}}
componentsProps={{
toolbar: { showQuickFilter: true },
}}
loading={loading}
checkboxSelection
disableSelectionOnClick
Expand Down
71 changes: 71 additions & 0 deletions docs/data/data-grid/filtering/QuickFilteringCustomLogic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DataGrid, GridToolbarQuickFilter } from '@mui/x-data-grid';

import { useDemoData } from '@mui/x-data-grid-generator';

function QuickSearchToolbar() {
return (
<Box
sx={{
p: 0.5,
pb: 0,
}}
>
<GridToolbarQuickFilter />
</Box>
);
}

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

const getApplyFilterFnSameYear = (value) => {
if (!value || value.length !== 4 || !/\d{4}/.test(value)) {
// If the value is not a 4 digit string, it can not be a year so applying this filter is useless
return null;
}
return (params) => {
return params.value.getFullYear() === Number(value);
};
};

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

// Otherwise filter will be applied on fields such as the hidden column id
const columns = React.useMemo(
() =>
data.columns
.filter((column) => VISIBLE_FIELDS.includes(column.field))
.map((column) => {
if (column.field === 'dateCreated') {
return {
...column,
getApplyQuickFilterFn: getApplyFilterFnSameYear,
};
}
if (column.field === 'name') {
return {
...column,
getApplyQuickFilterFn: undefined,
};
}
return column;
}),
[data.columns],
);

return (
<Box sx={{ height: 400, width: 1 }}>
<DataGrid
{...data}
columns={columns}
components={{ Toolbar: QuickSearchToolbar }}
/>
</Box>
);
}
71 changes: 71 additions & 0 deletions docs/data/data-grid/filtering/QuickFilteringCustomLogic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DataGrid, GridCellParams, GridToolbarQuickFilter } from '@mui/x-data-grid';

import { useDemoData } from '@mui/x-data-grid-generator';

function QuickSearchToolbar() {
return (
<Box
sx={{
p: 0.5,
pb: 0,
}}
>
<GridToolbarQuickFilter />
</Box>
);
}

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

const getApplyFilterFnSameYear = (value: string) => {
if (!value || value.length !== 4 || !/\d{4}/.test(value)) {
// If the value is not a 4 digit string, it can not be a year so applying this filter is useless
return null;
}
return (params: GridCellParams): boolean => {
return params.value.getFullYear() === Number(value);
};
};

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

// Otherwise filter will be applied on fields such as the hidden column id
const columns = React.useMemo(
() =>
data.columns
.filter((column) => VISIBLE_FIELDS.includes(column.field))
.map((column) => {
if (column.field === 'dateCreated') {
return {
...column,
getApplyQuickFilterFn: getApplyFilterFnSameYear,
};
}
if (column.field === 'name') {
return {
...column,
getApplyQuickFilterFn: undefined,
};
}
return column;
}),
[data.columns],
);

return (
<Box sx={{ height: 400, width: 1 }}>
<DataGrid
{...data}
columns={columns}
components={{ Toolbar: QuickSearchToolbar }}
/>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<DataGrid
{...data}
columns={columns}
components={{ Toolbar: QuickSearchToolbar }}
/>
63 changes: 63 additions & 0 deletions docs/data/data-grid/filtering/QuickFilteringCustomizedGrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import {
DataGrid,
GridToolbarQuickFilter,
GridLinkOperator,
} from '@mui/x-data-grid';

import { useDemoData } from '@mui/x-data-grid-generator';

function QuickSearchToolbar() {
return (
<Box
sx={{
p: 0.5,
pb: 0,
}}
>
<GridToolbarQuickFilter
quickFilterParser={(searchInput) =>
searchInput
.split(',')
.map((value) => value.trim())
.filter((value) => value !== '')
}
/>
</Box>
);
}

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

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

// Otherwise filter will be applied on fields such as the hidden column id
const columns = React.useMemo(
() => data.columns.filter((column) => VISIBLE_FIELDS.includes(column.field)),
[data.columns],
);

return (
<Box sx={{ height: 400, width: 1 }}>
<DataGrid
{...data}
columns={columns}
initialState={{
filter: {
filterModel: {
items: [],
quickFilterLogicOperator: GridLinkOperator.Or,
},
},
}}
components={{ Toolbar: QuickSearchToolbar }}
/>
</Box>
);
}
63 changes: 63 additions & 0 deletions docs/data/data-grid/filtering/QuickFilteringCustomizedGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import {
DataGrid,
GridToolbarQuickFilter,
GridLinkOperator,
} from '@mui/x-data-grid';

import { useDemoData } from '@mui/x-data-grid-generator';

function QuickSearchToolbar() {
return (
<Box
sx={{
p: 0.5,
pb: 0,
}}
>
<GridToolbarQuickFilter
quickFilterParser={(searchInput: string) =>
searchInput
.split(',')
.map((value) => value.trim())
.filter((value) => value !== '')
}
/>
</Box>
);
}

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

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

// Otherwise filter will be applied on fields such as the hidden column id
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
const columns = React.useMemo(
() => data.columns.filter((column) => VISIBLE_FIELDS.includes(column.field)),
[data.columns],
);

return (
<Box sx={{ height: 400, width: 1 }}>
<DataGrid
{...data}
columns={columns}
initialState={{
filter: {
filterModel: {
items: [],
quickFilterLogicOperator: GridLinkOperator.Or,
},
},
}}
components={{ Toolbar: QuickSearchToolbar }}
/>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<DataGrid
{...data}
columns={columns}
initialState={{
filter: {
filterModel: {
items: [],
quickFilterLogicOperator: GridLinkOperator.Or,
},
},
}}
components={{ Toolbar: QuickSearchToolbar }}
/>
Loading