diff --git a/src/components/Visualization/Visualization.js b/src/components/Visualization/Visualization.js index 1f7de45e9..b3c3376dc 100644 --- a/src/components/Visualization/Visualization.js +++ b/src/components/Visualization/Visualization.js @@ -260,18 +260,29 @@ export const Visualization = ({ } } - const { fetching, error, data } = useAnalyticsData({ + const analyticsArgs = { filters, visualization, isVisualizationLoading, displayProperty, onResponsesReceived, pageSize, - // Set first page directly for new visualization to avoid extra request with current page - page: visualization !== visualizationRef.current ? FIRST_PAGE : page, + page, sortField, sortDirection, - }) + } + + // Set first page and sorting directly for new visualization to avoid extra analytics requests + if (visualization !== visualizationRef.current) { + const { sortField, sortDirection } = getSorting(visualization) + + analyticsArgs.sortField = sortField + analyticsArgs.sortDirection = sortDirection + + analyticsArgs.page = FIRST_PAGE + } + + const { fetching, error, data } = useAnalyticsData(analyticsArgs) const fetchIndicatorTop = useMemo(() => { if (