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] Customize FilterPanel with props #3497

Merged
merged 40 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9afd3f4
add props to filter panel
alexfauquette Dec 22, 2021
129e939
add doc
alexfauquette Dec 22, 2021
0af7213
set default values
alexfauquette Dec 22, 2021
93e7aa3
small PR feedbacks
alexfauquette Jan 7, 2022
bd3fcdd
use class override for style modification
alexfauquette Jan 11, 2022
7651d6b
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Jan 11, 2022
3c9de83
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Jan 11, 2022
d421ad9
scripts
alexfauquette Jan 11, 2022
01dbe3e
markdownlint
alexfauquette Jan 11, 2022
5b50bf0
Apply suggestions from code review
alexfauquette Jan 17, 2022
3560f2b
typing feedbacks and avoid breaking changes
alexfauquette Jan 18, 2022
2855ab6
update classes names
alexfauquette Jan 18, 2022
d8c41ac
pass props to filterForm FormeControl
alexfauquette Jan 18, 2022
7d39cd8
proptypes
alexfauquette Jan 18, 2022
15630d7
remove required
alexfauquette Jan 18, 2022
87e656a
update doc explainations
alexfauquette Jan 18, 2022
1b16222
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Jan 26, 2022
3d7b052
update styling
alexfauquette Jan 26, 2022
3936174
update doc table
alexfauquette Jan 26, 2022
9d3e4fa
fix tests
alexfauquette Jan 26, 2022
8170224
add classes
alexfauquette Jan 26, 2022
7ff5e6c
match clesse properties with slot names
alexfauquette Jan 26, 2022
08225c9
update CSS doc
alexfauquette Jan 26, 2022
808261e
update doc example
alexfauquette Feb 1, 2022
00f7cd1
use styled without memo
alexfauquette Feb 1, 2022
9dcadb0
add label for outlined input
alexfauquette Feb 1, 2022
b2e6453
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Feb 2, 2022
7e659ab
docs:typescript:formatted
alexfauquette Feb 2, 2022
6c6d6a9
Jose feedback
alexfauquette Feb 7, 2022
84f4e16
mat feedbacks on typing
alexfauquette Feb 7, 2022
29bd314
language
alexfauquette Feb 7, 2022
6d5c487
yarn proptypes
alexfauquette Feb 7, 2022
72d2886
fix lint
alexfauquette Feb 7, 2022
64e7767
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Feb 8, 2022
04a5331
feedbacks
alexfauquette Feb 8, 2022
f10cb3d
add files removed during migration
alexfauquette Feb 8, 2022
7127c06
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Feb 10, 2022
3c8dbf7
Fix demo migration
alexfauquette Feb 10, 2022
ec687de
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Feb 10, 2022
cc8ef3e
Merge remote-tracking branch 'upstream/master' into customize-filters
alexfauquette Feb 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CustomToolbar.propTypes = {
setFilterButtonEl: PropTypes.func.isRequired,
};

export default function CustomFilterPanel() {
export default function CustomFilterPanelPosition() {
const { data } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CustomToolbar: React.FunctionComponent<{
</GridToolbarContainer>
);

export default function CustomFilterPanel() {
export default function CustomFilterPanelPosition() {
const { data } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
Expand Down
30 changes: 28 additions & 2 deletions docs/data/data-grid/filtering/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ In the demo below, the `rating` column only has the `<` and `>` operators.
### Edit an operator

The value used by the operator to look for has to be entered by the user.
On most column types, a text field is used. However, a custom component can be rendered instead.
On most column types, a text field is used.
However, a custom component can be rendered instead.

In the demo below, the `rating` column reuses the numeric operators but the rating component is used to enter the value of the filter.

Expand All @@ -259,9 +260,34 @@ const ratingColumnType: GridColTypeDef = {

You can customize the rendering of the filter panel as shown in [the component section](/components/data-grid/components/#overriding-components) of the documentation.

### Customize the filter panel content

The customization of the filter panel content can be performed by passing props to the default `<GridFilterPanel />` component.
The available props allow to override:

- The available `linkOperators` (can contains `GridLinkOperator.And` and `GridLinkOperator.Or`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already "available" in the previous line.

Suggested change
- The available `linkOperators` (can contains `GridLinkOperator.And` and `GridLinkOperator.Or`)
- The `linkOperators` (can contains `GridLinkOperator.And` and `GridLinkOperator.Or`)

- The order of the column selector (can be `"asc"` or `"desc"`)
- Any prop of the input components

Input components can be [customized](/customization/how-to-customize/) by using two approaches.
You can pass a `sx` prop to any input container or you can use css selectors on nested components of the filter panel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can pass a `sx` prop to any input container or you can use css selectors on nested components of the filter panel.
You can pass a `sx` prop to any input container or you can use CSS selectors on nested components of the filter panel.

More details are available in the demo.

| Props | Class |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Props | Class |
| Props | CSS class |

| :----------------------- | :---------------------------------------- |
| `deleteIconProps` | `MuiDataGrid-filterFormDeleteIcon` |
| `linkOperatorInputProps` | `MuiDataGrid-filterFormLinkOperatorInput` |
| `columnInputProps` | `MuiDataGrid-filterFormColumnInput` |
| `operatorInputProps` | `MuiDataGrid-filterFormOperatorInput` |
| `valueInputProps` | `MuiDataGrid-filterFormValueInput` |

{{"demo": "pages/components/data-grid/filtering/CustomFilterPanelContent.js", "bg": "inline"}}

### Customize the filter panel position

The demo below shows how to anchor the filter panel to the toolbar button instead of the column header.

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

## Server-side filter

Expand Down
5 changes: 5 additions & 0 deletions docs/pages/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@
"paper",
"editBooleanCell",
"filterForm",
"filterFormDeleteIcon",
"filterFormLinkOperatorInput",
"filterFormColumnInput",
"filterFormOperatorInput",
"filterFormValueInput",
"editInputCell",
"filterIcon",
"footerContainer",
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@
"paper",
"editBooleanCell",
"filterForm",
"filterFormDeleteIcon",
"filterFormLinkOperatorInput",
"filterFormColumnInput",
"filterFormOperatorInput",
"filterFormValueInput",
"editInputCell",
"filterIcon",
"footerContainer",
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@
"paper",
"editBooleanCell",
"filterForm",
"filterFormDeleteIcon",
"filterFormLinkOperatorInput",
"filterFormColumnInput",
"filterFormOperatorInput",
"filterFormValueInput",
"editInputCell",
"filterIcon",
"footerContainer",
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@
"paper",
"editBooleanCell",
"filterForm",
"filterFormDeleteIcon",
"filterFormLinkOperatorInput",
"filterFormColumnInput",
"filterFormOperatorInput",
"filterFormValueInput",
"editInputCell",
"filterIcon",
"footerContainer",
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the filter form component"
},
"filterFormDeleteIcon": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the delete icon of the filter form component"
},
"filterFormLinkOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the link operator inout of the filter form component"
},
"filterFormColumnInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column input of the filter form component"
},
"filterFormOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the operator input of the filter form component"
},
"filterFormValueInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the value input of the filter form component"
},
"editInputCell": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the input component"
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the filter form component"
},
"filterFormDeleteIcon": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the delete icon of the filter form component"
},
"filterFormLinkOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the link operator inout of the filter form component"
},
"filterFormColumnInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column input of the filter form component"
},
"filterFormOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the operator input of the filter form component"
},
"filterFormValueInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the value input of the filter form component"
},
"editInputCell": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the input component"
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the filter form component"
},
"filterFormDeleteIcon": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the delete icon of the filter form component"
},
"filterFormLinkOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the link operator inout of the filter form component"
},
"filterFormColumnInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column input of the filter form component"
},
"filterFormOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the operator input of the filter form component"
},
"filterFormValueInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the value input of the filter form component"
},
"editInputCell": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the input component"
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the filter form component"
},
"filterFormDeleteIcon": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the delete icon of the filter form component"
},
"filterFormLinkOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the link operator inout of the filter form component"
},
"filterFormColumnInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column input of the filter form component"
},
"filterFormOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the operator input of the filter form component"
},
"filterFormValueInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the value input of the filter form component"
},
"editInputCell": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the input component"
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the filter form component"
},
"filterFormDeleteIcon": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the delete icon of the filter form component"
},
"filterFormLinkOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the link operator inout of the filter form component"
},
"filterFormColumnInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column input of the filter form component"
},
"filterFormOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the operator input of the filter form component"
},
"filterFormValueInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the value input of the filter form component"
},
"editInputCell": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the input component"
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the filter form component"
},
"filterFormDeleteIcon": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the delete icon of the filter form component"
},
"filterFormLinkOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the link operator inout of the filter form component"
},
"filterFormColumnInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column input of the filter form component"
},
"filterFormOperatorInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the operator input of the filter form component"
},
"filterFormValueInput": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the value input of the filter form component"
},
"editInputCell": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the root of the input component"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import clsx from 'clsx';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import { styled } from '@mui/material/styles';
import { styled, Theme } from '@mui/material/styles';
import { MUIStyledCommonProps } from '@mui/system';
import { unstable_composeClasses as composeClasses } from '@mui/material';
import { getDataGridUtilityClass } from '../../gridClasses';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
Expand Down Expand Up @@ -34,9 +35,11 @@ const GridPanelWrapperRoot = styled('div', {

const isEnabled = () => true;

export function GridPanelWrapper(
props: React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>,
) {
interface GridPanelWrapperProps
extends React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>,
MUIStyledCommonProps<Theme> {}

function GridPanelWrapper(props: GridPanelWrapperProps) {
const { className, ...other } = props;
const rootProps = useGridRootProps();
const ownerState = { classes: rootProps.classes };
Expand All @@ -48,3 +51,5 @@ export function GridPanelWrapper(
</TrapFocus>
);
}

export { GridPanelWrapper };
Loading