diff --git a/.changeset/spicy-flowers-allow.md b/.changeset/spicy-flowers-allow.md new file mode 100644 index 000000000000..a280a1ca8142 --- /dev/null +++ b/.changeset/spicy-flowers-allow.md @@ -0,0 +1,7 @@ +--- +"@refinedev/core": patch +--- + +Update `useTable` hook to handle case where a user navigates to current page by clicking side-nav link intending to reset the filters and sorters. + +[Resolves #6300](https://github.com/refinedev/refine/issues/6300) diff --git a/packages/core/src/hooks/useTable/index.ts b/packages/core/src/hooks/useTable/index.ts index 7398aabc13a6..1a522ae72317 100644 --- a/packages/core/src/hooks/useTable/index.ts +++ b/packages/core/src/hooks/useTable/index.ts @@ -439,6 +439,28 @@ export function useTable< return `${pathname ?? ""}?${stringifyParams ?? ""}`; }; + useEffect(() => { + if (!parsedParams?.params?.filters && !parsedParams?.params?.sorters) { + const resetFilters = setInitialFilters( + preferredPermanentFilters, + defaultFilter ?? [], + ); + const resetSorters = setInitialSorters( + preferredPermanentSorters, + defaultSorter ?? [], + ); + + setFilters(resetFilters); + setSorters(resetSorters); + } + }, [ + parsedParams, + preferredPermanentFilters, + defaultFilter, + preferredPermanentSorters, + defaultSorter, + ]); + useEffect(() => { if (search === "") { setCurrent(defaultCurrent);