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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat(table): add show_search and a reusable mo.ui.table.Display config (#9984)
Kiran Gadhavea4b9d07bcdae
diff --git a/frontend/src/components/data-table/TableTopBar.tsx b/frontend/src/components/data-table/TableTopBar.tsxindex 052be468b2..fbf3fd5364 100644--- a/frontend/src/components/data-table/TableTopBar.tsx+++ b/frontend/src/components/data-table/TableTopBar.tsx@@ -27,7 +27,7 @@ const NOOP_ON_SEARCH = () => {interface TableTopBarProps<TData> extends Partial<ExportActionProps> {table: Table<TData>;- enableSearch: boolean;+ showSearch: boolean;searchQuery?: string;onSearchQueryChange?: (query: string) => void;reloading?: boolean;@@ -43,7 +43,7 @@ interface TableTopBarProps<TData> extends Partial<ExportActionProps> {export const TableTopBar = <TData,>({table,- enableSearch,+ showSearch,searchQuery,onSearchQueryChange,reloading,@@ -68,7 +68,7 @@ export const TableTopBar = <TData,>({return (<div className="flex items-center h-10 px-2 border-b gap-2">- {onSearchQueryChange && enableSearch && (+ {onSearchQueryChange && showSearch && (<div className="flex flex-1 items-center gap-1 px-2 rounded-sm focus-within:ring-1 focus-within:ring-border transition-shadow"><SearchIcon className="w-4 h-4 text-muted-foreground shrink-0" /><input@@ -99,7 +99,7 @@ export const TableTopBar = <TData,>({</div>)}- <div className="flex items-center shrink-0">+ <div className="flex items-center shrink-0 ml-auto"><ColumnVisibilityDropdown table={table} />{showChartBuilder && (<Buttondiff --git a/frontend/src/components/data-table/__tests__/data-table.test.tsx b/frontend/src/components/data-table/__tests__/data-table.test.tsxindex 5322003be9..a9180d2296 100644--- a/frontend/src/components/data-table/__tests__/data-table.test.tsx+++ b/frontend/src/components/data-table/__tests__/data-table.test.tsx@@ -69,6 +69,34 @@ describe("DataTable", () => {expect(commonProps.rowSelection).toEqual(initialRowSelection);});+ it("hides the search bar when showSearch is false", () => {+ const columns: ColumnDef<TestData>[] = [+ { accessorKey: "name", header: "Name" },+ ];+ const commonProps = {+ data: [{ id: 1, name: "Test 1" }] as TestData[],+ columns,+ totalRows: 1,+ totalColumns: 1,+ pagination: false,+ onSearchQueryChange: () => {},+ };++ const { rerender } = render(+ <TooltipProvider>+ <DataTable {...commonProps} showSearch={true} />+ </TooltipProvider>,+ );+ expect(screen.queryByPlaceholderText("Search...")).not.toBeNull();++ rerender(+ <TooltipProvider>+ <DataTable {...commonProps} showSearch={false} />+ </TooltipProvider>,+ );+ expect(screen.queryByPlaceholderText("Search...")).toBeNull();+ });+it("shows the hoverTemplate text as a styled tooltip on hover", async () => {vi.useFakeTimers();interface RowData {diff --git a/frontend/src/components/data-table/data-table.tsx b/frontend/src/components/data-table/data-table.tsxindex 44f3752405..07cad3b8bd 100644--- a/frontend/src/components/data-table/data-table.tsx+++ b/frontend/src/components/data-table/data-table.tsx@@ -104,7 +104,7 @@ interface DataTableProps<TData> extends Partial<ExportActionProps> {onCellSelectionChange?: OnChangeFn<CellSelectionState>;getRowIds?: GetRowIds;// Search- enableSearch?: boolean;+ showSearch?: boolean;searchQuery?: string;onSearchQueryChange?: (query: string) => void;showFilters?: boolean;@@ -159,7 +159,7 @@ const DataTableInternal = <TData,>({onRowSelectionChange,onCellSelectionChange,getRowIds,- enableSearch = false,+ showSearch = false,searchQuery,onSearchQueryChange,showFilters = false,@@ -357,7 +357,7 @@ const DataTableInternal = <TData,>({><TableTopBartable={table}- enableSearch={enableSearch}+ showSearch={showSearch}searchQuery={searchQuery}onSearchQueryChange={onSearchQueryChange}reloading={reloading}diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsxindex 156fe10a00..e760fe31ab 100644--- a/frontend/src/plugins/impl/DataTablePlugin.tsx+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx@@ -181,6 +181,7 @@ interface Data<T> {maxHeight?: number;selection: DataTableSelection;showDownload: boolean;+ showSearch: boolean;showFilters: boolean;showColumnSummaries: boolean | "stats" | "chart";showDataTypes: boolean;@@ -267,6 +268,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")showColumnExplorer: z.boolean().default(true),showRowExplorer: z.boolean().default(true),showChartBuilder: z.boolean().default(true),+ showSearch: z.boolean().default(true),rowHeaders: columnToFieldTypesSchema,freezeColumnsLeft: z.array(z.string()).optional(),freezeColumnsRight: z.array(z.string()).optional(),@@ -385,7 +387,6 @@ export const DataTablePlugin = createPlugin<S>("marimo-table"){...props.data}{...props.functions}host={props.host}- enableSearch={true}data={props.data.data}value={props.value}setValue={props.setValue}@@ -470,8 +471,6 @@ interface DataTableProps<T> extends Data<T>, DataTableFunctions {// Selectionvalue: S;setValue: (value: S) => void;- // Search- enableSearch: boolean;// FiltersenableFilters?: boolean;cellStyles?: CellStyleState | null;@@ -841,7 +840,7 @@ const DataTableComponent = ({setValue,sorting,setSorting,- enableSearch,+ showSearch,searchQuery,setSearchQuery,filters,@@ -1146,7 +1145,7 @@ const DataTableComponent = ({hoverTemplate={hoverTemplate}cellHoverTexts={cellHoverTexts}downloadAs={showDownload ? downloadAs : undefined}- enableSearch={enableSearch}+ showSearch={showSearch}searchQuery={searchQuery}onSearchQueryChange={setSearchQuery}showFilters={showFilters}diff --git a/frontend/src/plugins/impl/__tests__/DataTablePlugin.test.tsx b/frontend/src/plugins/impl/__tests__/DataTablePlugin.test.tsxindex 488a222ee9..657c237d82 100644--- a/frontend/src/plugins/impl/__tests__/DataTablePlugin.test.tsx+++ b/frontend/src/plugins/impl/__tests__/DataTablePlugin.test.tsx@@ -94,7 +94,7 @@ describe("LoadingDataTableComponent", () => {hasStableRowId: false,lazy: false,host,- enableSearch: true,+ showSearch: true,value: [] as (number | string | { rowId: string; columnName?: string })[],setValue,download_as: vi.fn() as DownloadAsArgs,diff --git a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsxindex c8be4cd045..f316585d6f 100644--- a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx+++ b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx@@ -338,7 +338,7 @@ export const DataFrameComponent = memo(showDownload={showDownload}download_as={download_as}get_size_bytes={get_size_bytes}- enableSearch={false}+ showSearch={false}showFilters={false}search={search}showColumnSummaries={false}diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.pyindex 3e936d5d95..3459e70184 100644--- a/marimo/_plugins/ui/_impl/table.py+++ b/marimo/_plugins/ui/_impl/table.py@@ -8,6 +8,7 @@ from typing import (Any,Final,Literal,+ TypedDict,Union,cast,)@@ -124,6 +125,37 @@ class ColumnSummaries:ShowColumnSummaries = bool | Literal["stats", "chart"]+++class TableDisplay(TypedDict, total=False):+ """Visibility options for `mo.ui.table` UI elements.++ All fields are optional; omitted fields fall back to the table's+ defaults. Build one and unpack it into one or more tables:++ ```python+ cfg = mo.ui.table.Display(show_search=False, show_download=False)+ mo.ui.table(data, **cfg)++ # Derive a variant; the original is unchanged+ mo.ui.table(other, **{**cfg, "show_column_summaries": False})+ ```++ Args:+ show_search (bool, optional): Whether to show the search bar.+ show_download (bool, optional): Whether to show the download button.+ show_column_summaries (bool | Literal["stats", "chart"], optional):+ Whether to show column summaries.+ show_data_types (bool, optional): Whether to show data type+ indicators in column headers.+ """++ show_search: bool+ show_download: bool+ show_column_summaries: ShowColumnSummaries+ show_data_types: bool++CHART_MAX_ROWS_STRING_VALUE_COUNTS = 20_000DEFAULT_MAX_COLUMNS = 50@@ -454,6 +486,8 @@ class table(Defaults to True.show_download (bool, optional): Whether to show the download button.Defaults to True for dataframes, False otherwise.+ show_search (bool, optional): Whether to show the search bar.+ Defaults to True.format_mapping (Dict[str, Union[str, Callable[..., Any]]], optional): A mapping fromcolumn names to formatting strings or functions.freeze_columns_left (Sequence[str], optional): List of column names to freeze on the left.@@ -485,6 +519,8 @@ class table(label (str, optional): A descriptive name for the table. Defaults to ""."""+ Display = TableDisplay+_name: Final[str] = "marimo-table"@staticmethod@@ -572,6 +608,7 @@ class table(show_download: bool = True,max_columns: MaxColumnsType = MAX_COLUMNS_NOT_PROVIDED,*,+ show_search: bool = True,label: str = "",on_change: Callable[[@@ -844,6 +881,7 @@ class table("show-filters": self._manager.supports_filters(),"show-download": show_downloadand self._manager.supports_download(),+ "show-search": show_search,"show-column-summaries": show_column_summaries,"show-data-types": show_data_types,"show-page-size-selector": show_page_size_selector,diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.pyindex 8ca3503a91..1c9c656929 100644--- a/tests/_plugins/ui/_impl/test_table.py+++ b/tests/_plugins/ui/_impl/test_table.py@@ -1423,6 +1423,45 @@ def test_show_download(df: Any) -> None:assert table_false._component_args["show-download"] is False+ "df",+ create_dataframes(+ {"a": [1, 2, 3], "b": [4, 5, 6]},+ ),+)+def test_show_search(df: Any) -> None:+ table_default = ui.table(df)+ assert table_default._component_args["show-search"] is True++ table_true = ui.table(df, show_search=True)+ assert table_true._component_args["show-search"] is True++ table_false = ui.table(df, show_search=False)+ assert table_false._component_args["show-search"] is False+++ "df",+ create_dataframes(+ {"a": [1, 2, 3], "b": [4, 5, 6]},+ ),+)+def test_display_config_unpacks(df: Any) -> None:+ cfg = ui.table.Display(show_search=False, show_download=False)+ assert cfg == {"show_search": False, "show_download": False}++ t = ui.table(df, **cfg)+ assert t._component_args["show-search"] is False+ assert t._component_args["show-download"] is False++ # Deriving a variant leaves the original untouched+ variant = {**cfg, "show_column_summaries": False}+ assert "show_column_summaries" not in cfg+ t2 = ui.table(df, **variant)+ assert t2._component_args["show-search"] is False+ assert t2._component_args["show-column-summaries"] is False++DOWNLOAD_FORMATS = ["csv", "tsv", "json", "parquet"]# Parquet export requires pandas+pyarrow or polars (see the `_download_as`@@ -2431,6 +2470,8 @@ def test_lazy_dataframe(df: Any) -> None:assert table._component_args["show-page-size-selector"] is Falseassert table._component_args["show-column-explorer"] is Falseassert table._component_args["show-chart-builder"] is False+ # Search is pushed down to the lazy backend, so it stays available.+ assert table._component_args["show-search"] is True# Verify that search response indicates "too_many" for total_rows# but returns the preview rows