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: pagination in mo.ui.table() when passed in manually (#2972)

Myles Scolnick4aeb8eecda74
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 28de7066fd..7e90ee545b 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -298,12 +298,14 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):
if pagination is False and total_rows != "too_many":
page_size = total_rows
- # pagination defaults to True if there are more than 10 rows
+ # pagination defaults to True if there are more than page_size rows
if pagination is None:
if total_rows == "too_many":
pagination = True
- elif total_rows > 10:
+ elif total_rows > page_size:
pagination = True
+ else:
+ pagination = False
# Search first page
search_result = self.search(
diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.py
index 154519c876..d6f1727d68 100644
--- a/tests/_plugins/ui/_impl/test_table.py
+++ b/tests/_plugins/ui/_impl/test_table.py
@@ -668,3 +668,33 @@ def test_show_download():
table_false = ui.table(data, show_download=False)
assert table_false._component_args["show-download"] is False
+
+
+def test_pagination_behavior() -> None:
+ # Test with default page_size=10
+ data = {"a": list(range(8))}
+ table = ui.table(data)
+ assert table._component_args["pagination"] is False
+ assert table._component_args["page-size"] == 10
+ assert len(table._component_args["data"]) == 8
+
+ # Test with custom page_size=5 and data <= page_size
+ data = {"a": list(range(5))}
+ table = ui.table(data, page_size=5)
+ assert table._component_args["pagination"] is False
+ assert table._component_args["page-size"] == 5
+ assert len(table._component_args["data"]) == 5
+
+ # Test with custom page_size=5 and data > page_size
+ data = {"a": list(range(8))}
+ table = ui.table(data, page_size=5)
+ assert table._component_args["pagination"] is True
+ assert table._component_args["page-size"] == 5
+ assert len(table._component_args["data"]) == 5
+
+ # Test with explicit pagination=True
+ data = {"a": list(range(5))}
+ table = ui.table(data, pagination=True, page_size=5)
+ assert table._component_args["pagination"] is True
+ assert table._component_args["page-size"] == 5
+ assert len(table._component_args["data"]) == 5