From d2c6ddf31590fe5f3c405ade89c0d4be393b2822 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 2 Jan 2025 11:33:57 +0100 Subject: [PATCH] Ignore default values for view sort --- .../grid/stores/datasources/viewV2.ts | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index 4dc5a44fd5..8b928364e1 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -151,6 +151,35 @@ export const initialise = (context: StoreContext) => { }) ) + function sortHasChanged( + newSort: { + column: string | null | undefined + order: SortOrder + }, + existingSort?: { + field: string + order?: SortOrder + } + ) { + const newColumn = newSort.column ?? null + const existingColumn = existingSort?.field ?? null + if (newColumn !== existingColumn) { + return true + } + + if (!newColumn) { + return false + } + + const newOrder = newSort.order ?? null + const existingOrder = existingSort?.order ?? null + if (newOrder !== existingOrder) { + return true + } + + return false + } + // When sorting changes, ensure view definition is kept up to date unsubscribers.push( sort.subscribe(async $sort => { @@ -161,10 +190,7 @@ export const initialise = (context: StoreContext) => { } // Skip if nothing actually changed - if ( - $sort?.column === $view.sort?.field && - $sort?.order === $view.sort?.order - ) { + if (!sortHasChanged($sort, $view.sort)) { return }