From c8b8eb2ff715122d17e502e08b603e58ac2cbf60 Mon Sep 17 00:00:00 2001 From: melloware Date: Sat, 24 Dec 2022 07:29:27 -0500 Subject: [PATCH] Fix #3819: Global filter not clearing --- components/lib/datatable/DataTable.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/lib/datatable/DataTable.js b/components/lib/datatable/DataTable.js index 0876e36058..34eaa6cdb9 100644 --- a/components/lib/datatable/DataTable.js +++ b/components/lib/datatable/DataTable.js @@ -2,7 +2,7 @@ import * as React from 'react'; import PrimeReact, { FilterMatchMode, FilterOperator, FilterService } from '../api/Api'; import { useEventListener, useMountEffect, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; import { Paginator } from '../paginator/Paginator'; -import { classNames, DomHandler, ObjectUtils, UniqueComponentId } from '../utils/Utils'; +import { DomHandler, ObjectUtils, UniqueComponentId, classNames } from '../utils/Utils'; import { VirtualScroller } from '../virtualscroller/VirtualScroller'; import { TableBody } from './TableBody'; import { TableFooter } from './TableFooter'; @@ -1015,6 +1015,10 @@ export const DataTable = React.forwardRef((props, ref) => { let localFiltered = false; for (let prop in filters) { + if (prop === 'null') { + continue; + } + if (Object.prototype.hasOwnProperty.call(filters, prop) && prop !== 'global') { localFiltered = true; let filterField = prop; @@ -1340,8 +1344,11 @@ export const DataTable = React.forwardRef((props, ref) => { useUpdateEffect(() => { if (props.globalFilter) { filter(props.globalFilter, 'global', props.globalFilterMatchMode); + } else { + // #3819 was filtering but now reset filter state + setFiltersState(props.filters); } - }, [props.globalFilter]); + }, [props.globalFilter, props.globalFilterMatchMode]); useUnmountEffect(() => { unbindColumnResizeEvents();