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: skip re-building content when embed_content=True #6881

Merged
merged 1 commit into from
May 30, 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
30 changes: 29 additions & 1 deletion panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_tabulator_expanded_content_pagination(document, comm):
assert len(model.children) == 0


def test_tabulator_expanded_content_embed(document, comm):
def test_tabulator_content_embed(document, comm):
df = makeMixedDataFrame()

table = Tabulator(df, embed_content=True, row_content=lambda r: r.A)
Expand All @@ -358,6 +358,34 @@ def test_tabulator_expanded_content_embed(document, comm):
assert row.text == f"<pre>{r.A+1}</pre>"


def test_tabulator_content_embed_and_expand(document, comm):
# https://github.com/holoviz/panel/issues/6200
df = makeMixedDataFrame()

calls = []
def row_content(row):
calls.append(row)
return row.A

table = Tabulator(df, embed_content=True, row_content=row_content)

model = table.get_root(document, comm)

assert len(calls) == len(df)

assert len(model.children) == len(df)

for i, r in df.iterrows():
assert i in model.children
row = model.children[i]
assert row.text == f"<pre>{r.A}</pre>"

# Expanding a row should not call row_content again in this context.
table.expanded = [1]

assert len(calls) == len(df)


def test_tabulator_selected_and_filtered_dataframe(document, comm):
df = makeMixedDataFrame()
table = Tabulator(df, selection=list(range(len(df))))
Expand Down
10 changes: 7 additions & 3 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,18 +1484,22 @@ def _indexes_changed(self, old, new):
def _update_children(self, *events):
cleanup, reuse = set(), set()
page_events = ('page', 'page_size', 'pagination')
old_panels = self._child_panels
for event in events:
if event.name == 'expanded' and len(events) == 1:
cleanup = set(event.old) - set(event.new)
reuse = set(event.old) & set(event.new)
if self.embed_content:
cleanup = set()
reuse = set(old_panels)
else:
cleanup = set(event.old) - set(event.new)
reuse = set(event.old) & set(event.new)
elif (
(event.name == 'value' and self._indexes_changed(event.old, event.new)) or
(event.name in page_events and not self._updating) or
(self.pagination == 'remote' and event.name == 'sorters')
):
self.expanded = []
return
old_panels = self._child_panels
self._child_panels = child_panels = self._get_children(
{i: old_panels[i] for i in reuse}
)
Expand Down
Loading