Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: table selection when being cleared (#2759)

Myles Scolnick7688b6ea8173
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index 1b43600bfa..f2e705a6a7 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -255,8 +255,9 @@ export const LoadingDataTableComponent = memo(
let tableData = props.data;
let totalRows = props.totalRows;
- // First page and no search query
- const shouldSkipSearch =
+ // If it is just the first page and no search query,
+ // we can show the initial page.
+ const canShowInitialPage =
searchQuery === "" &&
paginationState.pageIndex === 0 &&
filters.length === 0 &&
@@ -267,26 +268,32 @@ export const LoadingDataTableComponent = memo(
}
// If we have sort/search/filter, use the search function
- if (!shouldSkipSearch) {
- const searchResults = await search<T>({
- sort:
- sorting.length > 0
- ? {
- by: sorting[0].id,
- descending: sorting[0].desc,
- }
- : undefined,
- query: searchQuery,
- page_number: paginationState.pageIndex,
- page_size: paginationState.pageSize,
- filters: filters.flatMap((filter) => {
- return filterToFilterCondition(
- filter.id,
- filter.value as ColumnFilterValue,
- );
- }),
- });
+ const searchResultsPromise = search<T>({
+ sort:
+ sorting.length > 0
+ ? {
+ by: sorting[0].id,
+ descending: sorting[0].desc,
+ }
+ : undefined,
+ query: searchQuery,
+ page_number: paginationState.pageIndex,
+ page_size: paginationState.pageSize,
+ filters: filters.flatMap((filter) => {
+ return filterToFilterCondition(
+ filter.id,
+ filter.value as ColumnFilterValue,
+ );
+ }),
+ });
+ if (canShowInitialPage) {
+ // We still want to run the search,
+ // so the backend knows the current state for selection
+ // see https://github.com/marimo-team/marimo/issues/2756
+ void searchResultsPromise;
+ } else {
+ const searchResults = await searchResultsPromise;
tableData = searchResults.data;
totalRows = searchResults.total_rows;
}