Skip to content

Commit 5985fd3

Browse files
authored
fix: Prevent Tabulator page reset when clicking Last on a shrunk container (#8738)
1 parent 45cb9c1 commit 5985fd3

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

panel/models/tabulator.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,10 +827,20 @@ export class DataTabulatorView extends HTMLBoxView {
827827
if (!this.model.pagination || (this.model.page_size !== null && !this._automatic_page_size) || this._initializing || !this.tabulator) {
828828
return
829829
}
830-
this._automatic_page_size = true
831-
const responsive = this.model.sizing_mode && (this.model.sizing_mode.includes("height") || this.model.sizing_mode.includes("both"))
832830
const holder = this.shadow_el.querySelector(".tabulator-tableholder")
833831
const table = this.shadow_el.querySelector(".tabulator-table")
832+
if (
833+
this.model.page_size != null &&
834+
this.model.page >= this.model.max_page &&
835+
table != null &&
836+
table.children.length < this.model.page_size
837+
) {
838+
// Partial page: holder has shrunk to fit it, so its height doesn't
839+
// reflect full-page capacity. See https://github.com/holoviz/panel/issues/8737
840+
return
841+
}
842+
this._automatic_page_size = true
843+
const responsive = this.model.sizing_mode && (this.model.sizing_mode.includes("height") || this.model.sizing_mode.includes("both"))
834844
if (table != null && holder != null) {
835845
const table_height = holder.clientHeight
836846
let height = 0

panel/tests/ui/widgets/test_tabulator.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import datetime as dt
4+
import typing as t
45

56
from contextlib import contextmanager
67

@@ -3990,6 +3991,29 @@ def test_tabulator_local_pagination_page_size_preserved_on_value_none(page, df_m
39903991
expect(page.locator('.tabulator-row')).to_have_count(4)
39913992

39923993

3994+
def test_tabulator_local_pagination_auto_page_size_last_button(page):
3995+
# https://github.com/holoviz/panel/issues/8737
3996+
df = pd.DataFrame({'value': range(6401)})
3997+
widget = Tabulator(df, max_height=500, show_index=True)
3998+
3999+
serve_component(page, widget)
4000+
4001+
expect(page.locator('.tabulator-table')).to_have_count(1)
4002+
4003+
wait_until(lambda: bool(widget.page_size), page)
4004+
initial_page_size = t.cast("int", widget.page_size)
4005+
counts = count_per_page(len(df), initial_page_size)
4006+
last_page = len(counts)
4007+
4008+
page.locator('text="Last"').click()
4009+
page.wait_for_timeout(1000)
4010+
4011+
assert widget.page_size == initial_page_size
4012+
assert widget.page == last_page
4013+
expect(page.locator('.tabulator-row')).to_have_count(counts[-1])
4014+
expect(page.locator('.tabulator-row').last).to_contain_text(str(df['value'].iloc[-1]))
4015+
4016+
39934017
@pytest.mark.parametrize('pagination', ['local', 'remote', None])
39944018
def test_selection_indices_on_paginated_and_filtered_data(page, df_strings, pagination):
39954019
tbl = Tabulator(

0 commit comments

Comments
 (0)