dosubot[bot] commented on issue #30244:
URL: https://github.com/apache/superset/issues/30244#issuecomment-2344204928

   <!-- Greeting -->
   Hey @vineetdpnd! 👋 I'm here to help you with any bugs, questions, or 
contributions you have for Superset. Let's tackle this together!
   
   <!-- Answer -->
   To address the issue of pagination not resetting on charts after updating an 
applied filter, you can use the `useEffect` hook to clear the cache and reset 
the page index whenever the filters change. This is already implemented in the 
Superset codebase as follows:
   
   ```tsx
   // Clear cache and reset page index if filters change
   useEffect(() => {
     setResponseError('');
     setResultsPages(new Map());
     setPageIndex(0);
   }, [filters]);
   ```
   
   This `useEffect` hook ensures that whenever the `filters` state changes, the 
`responseError` is cleared, the `resultsPages` cache is reset, and the 
`pageIndex` is set to 0. This effectively resets the pagination to the first 
page, avoiding loading issues 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Chart/DrillDetail/DrillDetailPane.tsx)</sup>.
   
   Additionally, in the `buildQuery` function, there is logic to reset the 
`row_offset` to 0 if the filters have changed, ensuring that the pagination 
starts from the first page:
   
   ```ts
   if (
     formData.server_pagination &&
     options?.extras?.cachedChanges?.[formData.slice_id] &&
     JSON.stringify(options?.extras?.cachedChanges?.[formData.slice_id]) !==
       JSON.stringify(queryObject.filters)
   ) {
     queryObject = { ...queryObject, row_offset: 0 };
     updateExternalFormData(
       options?.hooks?.setDataMask,
       0,
       queryObject.row_limit ?? 0,
     );
   }
   ```
   
   This ensures that the pagination is reset on the server side as well, 
providing a consistent experience when filters are updated 
<sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to