Skip to content

Commit

Permalink
Fix various scrolling related Tabulator issues (#7076)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Aug 5, 2024
1 parent b10308b commit e7afa8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
39 changes: 29 additions & 10 deletions panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ export class DataTabulatorView extends HTMLBoxView {
_applied_styles: boolean = false
_building: boolean = false
_debounced_redraw: any = null
_restore_scroll: boolean = false
_restore_scroll: boolean | "horizontal" | "vertical" = false
_updating_scroll: boolean = false

override connect_signals(): void {
super.connect_signals()
Expand Down Expand Up @@ -396,18 +397,23 @@ export class DataTabulatorView extends HTMLBoxView {
if (this.tabulator === undefined) {
return
}
this._restore_scroll = "horizontal"
this._selection_updating = true
this._updating_scroll = true
this.setData()
this._updating_scroll = false
this._selection_updating = false
this.postUpdate()
})
this.connect(this.model.source.streaming, () => this.addData())
this.connect(this.model.source.patching, () => {
const inds = this.model.source.selected.indices
this._updating_scroll = true
this.updateOrAddData()
this.record_scroll()
this._updating_scroll = false
// Restore indices since updating data may have reset checkbox column
this.model.source.selected.indices = inds
this.restore_scroll()
})
this.connect(this.model.source.selected.change, () => this.setSelection())
this.connect(this.model.source.selected.properties.indices.change, () => this.setSelection())
Expand Down Expand Up @@ -1028,7 +1034,6 @@ export class DataTabulatorView extends HTMLBoxView {
}

// Update table

setData(): void {
if (this._initializing || this._building || !this.tabulator.initialized) {
return
Expand All @@ -1055,7 +1060,9 @@ export class DataTabulatorView extends HTMLBoxView {
this.setSelection()
this.setStyles()
if (this._restore_scroll) {
this.restore_scroll()
const vertical = this._restore_scroll === "horizontal" ? false : true
const horizontal = this._restore_scroll === "vertical" ? false : true
this.restore_scroll(horizontal, vertical)
this._restore_scroll = false
}
}
Expand Down Expand Up @@ -1203,18 +1210,30 @@ export class DataTabulatorView extends HTMLBoxView {
this._selection_updating = false
}

restore_scroll(): void {
const opts = {
top: this._lastVerticalScrollbarTopPosition,
left: this._lastHorizontalScrollbarLeftPosition,
behavior: "instant",
restore_scroll(horizontal: boolean=true, vertical: boolean=true): void {
if (!(horizontal || vertical)) {
return
}
setTimeout(() => this.tabulator.rowManager.element.scrollTo(opts), 0)
const opts: ScrollToOptions = {behavior: "instant"}
if (vertical) {
opts.top = this._lastVerticalScrollbarTopPosition
}
if (horizontal) {
opts.left = this._lastHorizontalScrollbarLeftPosition
}
setTimeout(() => {
this._updating_scroll = true
this.tabulator.rowManager.element.scrollTo(opts)
this._updating_scroll = false
}, 0)
}

// Update model

record_scroll() {
if (this._updating_scroll) {
return
}
this._lastVerticalScrollbarTopPosition = this.tabulator.rowManager.element.scrollTop
this._lastHorizontalScrollbarLeftPosition = this.tabulator.rowManager.element.scrollLeft
}
Expand Down
11 changes: 2 additions & 9 deletions panel/tests/ui/widgets/test_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,6 @@ def test_tabulator_frozen_rows(page):
assert Y_bb == page.locator('text="Y"').bounding_box()


@pytest.mark.xfail(reason='See https://github.com/holoviz/panel/issues/3669')
def test_tabulator_patch_no_horizontal_rescroll(page, df_mixed):
widths = 100
width = int(((df_mixed.shape[1] + 1) * widths) / 2)
Expand All @@ -1049,8 +1048,7 @@ def test_tabulator_patch_no_horizontal_rescroll(page, df_mixed):
# Catch a potential rescroll
page.wait_for_timeout(400)
# The table should keep the same scroll position
# This fails
assert bb == page.locator('text="tomodify"').bounding_box()
wait_until(lambda: bb == page.locator('text="tomodify"').bounding_box(), page)


@pytest.mark.xfail(reason='See https://github.com/holoviz/panel/issues/3249')
Expand Down Expand Up @@ -1113,12 +1111,7 @@ def test_tabulator_patch_no_height_resize(page):


@pytest.mark.parametrize(
'pagination',
(
pytest.param('local', marks=pytest.mark.xfail(reason='See https://github.com/holoviz/panel/issues/3553')),
pytest.param('remote', marks=pytest.mark.xfail(reason='See https://github.com/holoviz/panel/issues/3553')),
None,
)
'pagination', ('local', 'remote', None)
)
def test_tabulator_header_filter_no_horizontal_rescroll(page, df_mixed, pagination):
widths = 100
Expand Down

0 comments on commit e7afa8a

Please sign in to comment.