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

fix(core): reset table filters and sorters on current page re-navigate via side-nav #6389

Closed
7 changes: 7 additions & 0 deletions .changeset/spicy-flowers-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/core": major
arndom marked this conversation as resolved.
Show resolved Hide resolved
---

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)
22 changes: 22 additions & 0 deletions packages/core/src/hooks/useTable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading