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

Allow Tabulator HTMLTemplateFormatter to reference multiple columns #6663

Merged
merged 2 commits into from
Apr 4, 2024
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
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
Loading