From d82cd0e4afb12bf5ea1be0c8efeb8d82831e5917 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 13 May 2021 13:11:45 +0100 Subject: [PATCH] Wait until table schema loads before searching to avoid initial double search --- .../src/DataProvider.svelte | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/standard-components/src/DataProvider.svelte b/packages/standard-components/src/DataProvider.svelte index 64e387462a..66414ac39b 100644 --- a/packages/standard-components/src/DataProvider.svelte +++ b/packages/standard-components/src/DataProvider.svelte @@ -17,6 +17,7 @@ // Loading flag for the initial load let loaded = false + let schemaLoaded = false // Provider state let rows = [] @@ -31,16 +32,23 @@ $: hasPrevPage = pageNumber > 0 $: getSchema(dataSource) $: sortType = getSortType(schema, sortColumn) - $: fetchData( - dataSource, - query, - limit, - sortColumn, - sortOrder, - sortType, - paginate - ) $: { + // Wait until schema loads before loading data, so that we can determine + // the correct sort type first time + if (schemaLoaded) { + fetchData( + dataSource, + query, + limit, + sortColumn, + sortOrder, + sortType, + paginate + ) + } + } + $: { + // Sort and limit rows in memory when we aren't searching internal tables if (internalTable) { rows = allRows } else { @@ -195,6 +203,7 @@ } }) schema = fixedSchema + schemaLoaded = true } const nextPage = async () => {