diff --git a/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx b/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx index 6c19ae5f9b37..bd8aca4630ed 100644 --- a/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx +++ b/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx @@ -167,7 +167,7 @@ const GridHeaderFilterCell = React.forwardRef { - if (item.value && !updatedItem.value) { + if (item.value && updatedItem.value === undefined) { apiRef.current.deleteFilterItem(updatedItem); return; } @@ -314,7 +314,7 @@ const GridHeaderFilterCell = React.forwardRef - Filter', () => { ); }).not.toErrorDev(); }); + + it('should work correctly with boolean column type', () => { + const getRows = (item: Omit) => { + const { unmount } = render( + { + const value = params.value as boolean | null | undefined; + + if (value === null) { + return 'null'; + } + + if (value === undefined) { + return 'undefined'; + } + + return value.toString(); + }, + }, + ]} + headerFilters + />, + ); + const values = getColumnValues(0); + unmount(); + return values; + }; + const ALL_ROWS = ['undefined', 'null', 'true', 'false']; + const TRUTHY_ROWS = ['true']; + const FALSY_ROWS = ['undefined', 'null', 'false']; + + expect(getRows({ operator: 'is', value: 'true' })).to.deep.equal(TRUTHY_ROWS); + expect(getRows({ operator: 'is', value: true })).to.deep.equal(TRUTHY_ROWS); + + expect(getRows({ operator: 'is', value: 'false' })).to.deep.equal(FALSY_ROWS); + expect(getRows({ operator: 'is', value: false })).to.deep.equal(FALSY_ROWS); + + expect(getRows({ operator: 'is', value: '' })).to.deep.equal(ALL_ROWS); + expect(getRows({ operator: 'is', value: undefined })).to.deep.equal(ALL_ROWS); + expect(getRows({ operator: 'is', value: null })).to.deep.equal(ALL_ROWS); + expect(getRows({ operator: 'is', value: 'test' })).to.deep.equal(ALL_ROWS); // Ignores invalid values + }); }); describe('Read-only filters', () => { diff --git a/packages/x-data-grid/src/tests/filtering.DataGrid.test.tsx b/packages/x-data-grid/src/tests/filtering.DataGrid.test.tsx index 6aff1383998a..5e333fd3765b 100644 --- a/packages/x-data-grid/src/tests/filtering.DataGrid.test.tsx +++ b/packages/x-data-grid/src/tests/filtering.DataGrid.test.tsx @@ -1127,6 +1127,7 @@ describe(' - Filter', () => { expect(getRows({ operator: 'is', value: '' })).to.deep.equal(ALL_ROWS); expect(getRows({ operator: 'is', value: undefined })).to.deep.equal(ALL_ROWS); + expect(getRows({ operator: 'is', value: null })).to.deep.equal(ALL_ROWS); expect(getRows({ operator: 'is', value: 'test' })).to.deep.equal(ALL_ROWS); // Ignores invalid values }); });