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

Tabulator: HTMLTemplateFormatter not working when referencing other columns #6654

Closed
maximlt opened this issue Apr 3, 2024 · 0 comments · Fixed by #6663
Closed

Tabulator: HTMLTemplateFormatter not working when referencing other columns #6654

maximlt opened this issue Apr 3, 2024 · 0 comments · Fixed by #6663
Labels
component: tabulator Related to the Tabulator widget type: bug Something isn't correct or isn't working
Milestone

Comments

@maximlt
Copy link
Member

maximlt commented Apr 3, 2024

from datetime import datetime
import panel as pn
import pandas as pd
from bokeh.models import HTMLTemplateFormatter

pn.extension('tabulator')

htmlfmt = HTMLTemplateFormatter(
    template='<%= X %> <%= value %>'
)

df = pd.DataFrame({
    'W': [datetime.now(), datetime.now(), datetime.now()],
    'X': ['aaa', 'bbb', 'ccc'],
    'Y': ['111', '222', '333'],
    'Z': [0, 1, 2],
})

# pn.widgets.DataFrame(
pn.widgets.Tabulator(
    df,
    formatters={'Y': htmlfmt},
).servable()

image

Web console traceback:

Uncaught (in promise) ReferenceError: X is not defined
    at eval (eval at h.template (bokeh-tables.min.js?v=21eea25553985e6a1d89f7fd52911752721d20b436701249917fc76f5464936d10c1f5005d504479c6540681d83b84e584f94a096c58f3cbd94d48d7a077990a:55:1989), <anonymous>:6:9)
    at o (bokeh-tables.min.js?v=21eea25553985e6a1d89f7fd52911752721d20b436701249917fc76f5464936d10c1f5005d504479c6540681d83b84e584f94a096c58f3cbd94d48d7a077990a:55:2101)
    at E.doFormat (bokeh-tables.min.js?v=21eea25553985e6a1d89f7fd52911752721d20b436701249917fc76f5464936d10c1f5005d504479c6540681d83b84e584f94a096c58f3cbd94d48d7a077990a:50:4333)
    at s.formatter (panel.min.js?v=fd49dd7ffc1373c0b731ba07c08299615cc2634d5cf07047e8b7cf847d27b74f:62:13703)
    at re.formatValue (Format.js:135:47)
    at InternalEventBus.js:76:33
    at Array.forEach (<anonymous>)
    at y._chain (InternalEventBus.js:75:21)
    at o.chain (CoreFeature.js:82:30)
    at o._generateContents (Cell.js:99:14)

But it works with the DataFrame widget:

image


After a quick search I think the issue is in this line where formatting should be given the dataContext to access the values from other rows. No idea how straightforward it is to implement that. I hope I can find some time to look more into it this week.

https://github.com/holoviz/panel/blob/v1.4.1a1/panel/models/tabulator.ts#L856


It was already reported on Discourse a while back: https://discourse.holoviz.org/t/using-tabulator-bokeh-htmltemplateformatter-to-create-a-cell-that-uses-another-columns-data-as-the-link/5355

@maximlt maximlt added TRIAGE Default label for untriaged issues type: bug Something isn't correct or isn't working component: tabulator Related to the Tabulator widget and removed TRIAGE Default label for untriaged issues labels Apr 3, 2024
@philippjfr philippjfr added this to the v1.4.1 milestone Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabulator Related to the Tabulator widget type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants