Skip to content

Commit

Permalink
fix: pagination when is custom
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Nov 26, 2024
1 parent b24bed3 commit b0255ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions marimo/_plugins/ui/_impl/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,14 @@ def __init__(

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(
Expand Down
30 changes: 30 additions & 0 deletions tests/_plugins/ui/_impl/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b0255ae

Please sign in to comment.