Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign Tabulator styles handling #3175

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/models/tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DataTabulator(HTMLBox):

source = Instance(ColumnDataSource)

styles = Dict(Int, Dict(Int, List(Either(String, Tuple(String, String)))))
styles = Dict(String, Either(String, Dict(Int, Dict(Int, List(Either(String, Tuple(String, String)))))))

pagination = Nullable(String)

Expand Down
30 changes: 7 additions & 23 deletions panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ export class DataTabulatorView extends PanelHTMLBoxView {
_updating_page: boolean = true
_relayouting: boolean = false
_selection_updating: boolean =false
_styled_cells: any[] = []
_styles: any = null
_initializing: boolean

connect_signals(): void {
Expand All @@ -259,11 +257,7 @@ export class DataTabulatorView extends PanelHTMLBoxView {
}
})

this.connect(this.model.properties.styles.change, () => {
this._styles = this.model.styles
this.setStyles()
})

this.connect(this.model.properties.styles.change, () => this.setStyles())
this.connect(this.model.properties.hidden_columns.change, () => this.setHidden())
this.connect(this.model.properties.page_size.change, () => this.setPageSize())
this.connect(this.model.properties.page.change, () => {
Expand Down Expand Up @@ -297,9 +291,8 @@ export class DataTabulatorView extends PanelHTMLBoxView {

after_layout(): void {
super.after_layout()
if (this.tabulator != null && (!this._relayouting || this._initializing)) {
if (this.tabulator != null && (!this._relayouting || this._initializing))
this.redraw()
}
}

render(): void {
Expand All @@ -308,8 +301,6 @@ export class DataTabulatorView extends PanelHTMLBoxView {
if (wait)
return
this._initializing = true
if (this._styles == null)
this._styles = this.model.styles
const container = div({class: "pnx-tabulator"})
set_size(container, this.model)
let configuration = this.getConfiguration()
Expand All @@ -335,7 +326,7 @@ export class DataTabulatorView extends PanelHTMLBoxView {
} else
this.setFrozen()

this.el.appendChild(container);
this.el.appendChild(container)
}

/*
Expand Down Expand Up @@ -807,6 +798,7 @@ export class DataTabulatorView extends PanelHTMLBoxView {

let data = transform_cds_to_records(this.model.source, true)
this.tabulator.setData(data)
console.log('update')
this.postUpdate()
}

Expand Down Expand Up @@ -876,13 +868,10 @@ export class DataTabulatorView extends PanelHTMLBoxView {
}

setStyles(): void {
for (const cell_el of this._styled_cells)
cell_el.cssText = ""
this._styled_cells = []
if (this._styles == null || this.tabulator == null || this.tabulator.getDataCount() == 0)
if (this.tabulator == null || this.tabulator.getDataCount() == 0)
return
for (const r in this._styles) {
const row_style = this._styles[r]
for (const r in this.model.styles.data) {
const row_style = this.model.styles.data[r]
const row = this.tabulator.getRow(r)
if (!row)
continue
Expand All @@ -893,8 +882,6 @@ export class DataTabulatorView extends PanelHTMLBoxView {
if (cell == null || !style.length)
continue
const element = cell.element
this._styled_cells.push(element)
element.cssText = ""
for (const s of style) {
let prop, value
if (isArray(s))
Expand All @@ -907,9 +894,6 @@ export class DataTabulatorView extends PanelHTMLBoxView {
}
}
}
const styles = this._styles
this.model.styles = {}
this._styles = styles
}

setHidden(): void {
Expand Down
2 changes: 1 addition & 1 deletion panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def high_red(value):

model = table.get_root(document, comm)

assert model.styles == {
assert model.styles['data'] == {
0: {1: [('color', 'black')]},
1: {1: [('color', 'black')]},
2: {1: [('color', 'black')]},
Expand Down
3 changes: 2 additions & 1 deletion panel/widgets/tables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
import uuid

from functools import partial
from types import FunctionType, MethodType
Expand Down Expand Up @@ -1067,7 +1068,7 @@ def _get_style_data(self, recompute=True):
if r not in styles:
styles[int(r)] = {}
styles[int(r)][offset+int(c)] = s
return styles
return {'id': uuid.uuid4().hex, 'data': styles}

def _get_selectable(self):
if self.value is None or self.selectable_rows is None:
Expand Down