From 8b144b673087d8078a4721fb70848f2d12927e2e Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Tue, 15 Oct 2024 09:51:56 -0700 Subject: [PATCH 1/3] limit tabulator height with max height --- panel/models/tabulator.ts | 2 +- panel/tests/ui/widgets/test_tabulator.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/panel/models/tabulator.ts b/panel/models/tabulator.ts index c6221c8309..14489ef330 100644 --- a/panel/models/tabulator.ts +++ b/panel/models/tabulator.ts @@ -562,7 +562,7 @@ export class DataTabulatorView extends HTMLBoxView { this._initializing = true this._building = true const container = div({style: {display: "contents"}}) - const el = div({style: {width: "100%", height: "100%", visibility: "hidden"}}) + const el = div({style: {width: "100%", height: "100%", maxHeight: this.model.max_height ? `${this.model.max_height}px` : "100%", visibility: "hidden"}}) this.container = el this.setCSSClasses(el) container.appendChild(el) diff --git a/panel/tests/ui/widgets/test_tabulator.py b/panel/tests/ui/widgets/test_tabulator.py index 959e9a9d24..7e18ee3da8 100644 --- a/panel/tests/ui/widgets/test_tabulator.py +++ b/panel/tests/ui/widgets/test_tabulator.py @@ -1159,6 +1159,17 @@ def test_tabulator_patch_no_height_resize(page): wait_until(lambda: page.locator('.pnx-tabulator').evaluate(at_bottom_script), page) +def test_tabulator_max_height_not_overlap(page): + df = pd.DataFrame({'col': np.random.random(100)}) + widget = Tabulator(df, max_height=200) + + serve_component(page, widget) + + table = page.locator('.pnx-tabulator') + expect(table).to_have_css('max-height', '200px') + assert table.bounding_box()['height'] <= 200 + + @pytest.mark.parametrize( 'pagination', ('local', 'remote', None) ) From 2f9052e4d624f1f477a36ed3cd5a33a68f28f35a Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Tue, 15 Oct 2024 10:19:04 -0700 Subject: [PATCH 2/3] use maxHeight config --- panel/models/tabulator.ts | 5 ++++- panel/tests/ui/widgets/test_tabulator.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/panel/models/tabulator.ts b/panel/models/tabulator.ts index 14489ef330..3cc745b2a3 100644 --- a/panel/models/tabulator.ts +++ b/panel/models/tabulator.ts @@ -562,7 +562,7 @@ export class DataTabulatorView extends HTMLBoxView { this._initializing = true this._building = true const container = div({style: {display: "contents"}}) - const el = div({style: {width: "100%", height: "100%", maxHeight: this.model.max_height ? `${this.model.max_height}px` : "100%", visibility: "hidden"}}) + const el = div({style: {width: "100%", height: "100%", visibility: "hidden"}}) this.container = el this.setCSSClasses(el) container.appendChild(el) @@ -781,6 +781,9 @@ export class DataTabulatorView extends HTMLBoxView { }, rowFormatter: (row: any) => this._render_row(row, false), } + if (this.model.max_height != null) { + configuration.maxHeight = this.model.max_height + } if (this.model.pagination === "remote") { configuration.ajaxURL = "http://panel.pyviz.org" configuration.sortMode = "remote" diff --git a/panel/tests/ui/widgets/test_tabulator.py b/panel/tests/ui/widgets/test_tabulator.py index 7e18ee3da8..f7c3087d33 100644 --- a/panel/tests/ui/widgets/test_tabulator.py +++ b/panel/tests/ui/widgets/test_tabulator.py @@ -1159,7 +1159,7 @@ def test_tabulator_patch_no_height_resize(page): wait_until(lambda: page.locator('.pnx-tabulator').evaluate(at_bottom_script), page) -def test_tabulator_max_height_not_overlap(page): +def test_tabulator_max_height_set(page): df = pd.DataFrame({'col': np.random.random(100)}) widget = Tabulator(df, max_height=200) @@ -1170,6 +1170,21 @@ def test_tabulator_max_height_not_overlap(page): assert table.bounding_box()['height'] <= 200 +def test_tabulator_max_height_unset(page): + """ + If max_height is not set, Tabulator should not set it to null; + else there's some recursion issues in the console and lag + """ + df = pd.DataFrame({'col': np.random.random(100)}) + widget = Tabulator(df) + + serve_component(page, widget) + + table = page.locator('.pnx-tabulator') + expect(table).not_to_have_css('max-height', '200px') + assert table.bounding_box()['height'] >= 200 + + @pytest.mark.parametrize( 'pagination', ('local', 'remote', None) ) From d70d43b0a83c7f25d7ba59e016f24f0c30ba3c5e Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Tue, 15 Oct 2024 11:16:34 -0700 Subject: [PATCH 3/3] reverse logic --- panel/tests/ui/widgets/test_tabulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panel/tests/ui/widgets/test_tabulator.py b/panel/tests/ui/widgets/test_tabulator.py index f7c3087d33..8663a597f2 100644 --- a/panel/tests/ui/widgets/test_tabulator.py +++ b/panel/tests/ui/widgets/test_tabulator.py @@ -1181,7 +1181,7 @@ def test_tabulator_max_height_unset(page): serve_component(page, widget) table = page.locator('.pnx-tabulator') - expect(table).not_to_have_css('max-height', '200px') + expect(table).to_have_css('max-height', 'none') assert table.bounding_box()['height'] >= 200