Skip to content

Commit

Permalink
[DataGrid] Display column's filter icon if a filter is applied (mui#4120
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DanailH authored Mar 9, 2022
1 parent 5e55a35 commit d7daee6
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/pages/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
"columnHeader--numeric",
"columnHeader--sortable",
"columnHeader--sorted",
"columnHeader--filtered",
"columnHeader",
"columnHeaderCheckbox",
"columnHeaderDraggableContainer",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
"columnHeader--numeric",
"columnHeader--sortable",
"columnHeader--sorted",
"columnHeader--filtered",
"columnHeader",
"columnHeaderCheckbox",
"columnHeaderDraggableContainer",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
"columnHeader--numeric",
"columnHeader--sortable",
"columnHeader--sorted",
"columnHeader--filtered",
"columnHeader",
"columnHeaderCheckbox",
"columnHeaderDraggableContainer",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
"columnHeader--numeric",
"columnHeader--sortable",
"columnHeader--sorted",
"columnHeader--filtered",
"columnHeader",
"columnHeaderCheckbox",
"columnHeaderDraggableContainer",
Expand Down
5 changes: 5 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 @@ -218,6 +218,11 @@
"nodeName": "the column header",
"conditions": "the column is sorted"
},
"columnHeader--filtered": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header element"
Expand Down
5 changes: 5 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 @@ -218,6 +218,11 @@
"nodeName": "the column header",
"conditions": "the column is sorted"
},
"columnHeader--filtered": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header element"
Expand Down
5 changes: 5 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 @@ -218,6 +218,11 @@
"nodeName": "the column header",
"conditions": "the column is sorted"
},
"columnHeader--filtered": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header element"
Expand Down
5 changes: 5 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 @@ -187,6 +187,11 @@
"nodeName": "the column header",
"conditions": "the column is sorted"
},
"columnHeader--filtered": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header element"
Expand Down
5 changes: 5 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 @@ -187,6 +187,11 @@
"nodeName": "the column header",
"conditions": "the column is sorted"
},
"columnHeader--filtered": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header element"
Expand Down
5 changes: 5 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@
"nodeName": "the column header",
"conditions": "the column is sorted"
},
"columnHeader--filtered": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header element"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ type OwnerState = GridColumnHeaderItemProps & {
};

const useUtilityClasses = (ownerState: OwnerState) => {
const { column, classes, isDragging, sortDirection, showRightBorder } = ownerState;
const { column, classes, isDragging, sortDirection, showRightBorder, filterItemsCounter } =
ownerState;

const isColumnSorted = sortDirection != null;
const isColumnFiltered = filterItemsCounter != null && filterItemsCounter > 0;
// todo refactor to a prop on col isNumeric or ?? ie: coltype===price wont work
const isColumnNumeric = column.type === 'number';

Expand All @@ -59,6 +61,7 @@ const useUtilityClasses = (ownerState: OwnerState) => {
column.sortable && 'columnHeader--sortable',
isDragging && 'columnHeader--moving',
isColumnSorted && 'columnHeader--sorted',
isColumnFiltered && 'columnHeader--filtered',
isColumnNumeric && 'columnHeader--numeric',
showRightBorder && 'withBorder',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ export const GridRootStyles = styled('div', {
display: 'flex',
alignItems: 'center',
},
[`& .${gridClasses['columnHeader--sorted']} .${gridClasses.iconButtonContainer}`]: {
visibility: 'visible',
width: 'auto',
},
[`& .${gridClasses['columnHeader--sorted']} .${gridClasses.iconButtonContainer}, & .${gridClasses['columnHeader--filtered']} .${gridClasses.iconButtonContainer}`]:
{
visibility: 'visible',
width: 'auto',
},
[`& .${gridClasses.columnHeader}:not(.${gridClasses['columnHeader--sorted']}) .${gridClasses.sortIcon}`]:
{
opacity: 0,
Expand Down
5 changes: 5 additions & 0 deletions packages/grid/x-data-grid/src/constants/gridClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export interface GridClasses {
* Styles applied to the column header if the column is sorted.
*/
'columnHeader--sorted': string;
/**
* Styles applied to the column header if the column has a filter applied to it.
*/
'columnHeader--filtered': string;
/**
* Styles applied to the column header element.
*/
Expand Down Expand Up @@ -400,6 +404,7 @@ export const gridClasses = generateUtilityClasses('MuiDataGrid', [
'columnHeader--numeric',
'columnHeader--sortable',
'columnHeader--sorted',
'columnHeader--filtered',
'columnHeader',
'columnHeaderCheckbox',
'columnHeaderDraggableContainer',
Expand Down

0 comments on commit d7daee6

Please sign in to comment.