Skip to content

Commit

Permalink
Allow Tabulator HTMLTemplateFormatter to reference multiple columns (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Apr 4, 2024
1 parent 27e75ed commit a417daa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,8 @@ export class DataTabulatorView extends HTMLBoxView {
tab_column.formatter = "tickCross"
} else {
tab_column.formatter = (cell: any) => {
const formatted = column.formatter.doFormat(cell.getRow(), cell, cell.getValue(), null, null)
const row = cell.getRow()
const formatted = column.formatter.doFormat(cell.getRow(), cell, cell.getValue(), null, row.getData())
if (column.formatter.type === "HTMLTemplateFormatter") {
return formatted
}
Expand Down
17 changes: 17 additions & 0 deletions panel/tests/ui/widgets/test_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,23 @@ def test_tabulator_formatters_bokeh_string(page, df_mixed):
)


def test_tabulator_formatters_bokeh_html_multiple_columns(page, df_mixed):
htmlfmt = HTMLTemplateFormatter(
template='<p class="html-format"><%= str %> <%= bool %></p>'
)
widget = Tabulator(df_mixed, formatters={'str': htmlfmt})

serve_component(page, widget)

# The BooleanFormatter renders with svg icons.
cells = page.locator(".tabulator-cell .html-format")
expect(cells).to_have_count(len(df_mixed))

for i, (_, row) in enumerate(df_mixed.iterrows()):

expect(cells.nth(i)).to_have_text(f"{row['str']} {str(row['bool']).lower()}")


def test_tabulator_formatters_bokeh_html(page, df_mixed):
widget = Tabulator(
df_mixed,
Expand Down

0 comments on commit a417daa

Please sign in to comment.