Skip to content

Commit

Permalink
Make Tabulator resize handling more robust (#6821)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored May 13, 2024
1 parent 9db65b2 commit c7d5994
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
with:
name: unit_test_suite
python-version: ${{ matrix.python-version }}
channels: pyviz/label/dev,numba,conda-forge,nodefaults
channels: pyviz/label/dev,numba,bokeh,conda-forge,nodefaults
conda-update: true
nodejs: true
nodejs-version: "20.9" # https://github.com/bokeh/bokeh/pull/13851
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
with:
name: ui_test_suite
python-version: 3.9
channels: pyviz/label/dev,conda-forge,nodefaults
channels: pyviz/label/dev,bokeh,conda-forge,nodefaults
envs: "-o recommended -o tests -o build"
cache: ${{ github.event.inputs.cache || github.event.inputs.cache == '' }}
nodejs: true
Expand Down
19 changes: 18 additions & 1 deletion panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export class DataTabulatorView extends HTMLBoxView {

tabulator: any
columns: Map<string, any> = new Map()
container: HTMLDivElement | null = null
_tabulator_cell_updating: boolean=false
_updating_page: boolean = false
_updating_sort: boolean = false
Expand All @@ -317,11 +318,13 @@ export class DataTabulatorView extends HTMLBoxView {
_lastHorizontalScrollbarLeftPosition: number = 0
_applied_styles: boolean = false
_building: boolean = false
_debounced_redraw: any = null
_restore_scroll: boolean = false

override connect_signals(): void {
super.connect_signals()

this._debounced_redraw = debounce(() => this._resize_redraw(), 20, false)
const {
configuration, layout, columns, groupby, visible, download,
children, expanded, cell_styles, hidden_columns, page_size,
Expand Down Expand Up @@ -467,7 +470,20 @@ export class DataTabulatorView extends HTMLBoxView {

override after_resize(): void {
super.after_resize()
this.redraw(false, true)
this._debounced_redraw()
}

_resize_redraw(): void {
if (this._initializing || !this.container || this._building) {
return
}
const width = this.container.clientWidth
const height = this.container.clientHeight
if (!width || !height) {
return
}
this.redraw(true, true)
this.restore_scroll()
}

setCSSClasses(el: HTMLDivElement): void {
Expand All @@ -485,6 +501,7 @@ export class DataTabulatorView extends HTMLBoxView {
this._initializing = true
const container = div({style: "display: contents;"})
const el = div({style: "width: 100%; height: 100%; visibility: hidden;"})
this.container = el
this.setCSSClasses(el)
container.appendChild(el)
this.shadow_el.appendChild(container)
Expand Down

0 comments on commit c7d5994

Please sign in to comment.