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

Do no reset Tabulator if DataFrame indexes are unchanged #5436

Merged
merged 2 commits into from
Aug 25, 2023
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: 0 additions & 2 deletions panel/models/reactive_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {useCallback} from 'preact/hooks';
import {html} from 'htm/preact';

import {div} from "@bokehjs/core/dom"
import {build_views} from "@bokehjs/core/build_views"
import {isArray} from "@bokehjs/core/util/types"
import * as p from "@bokehjs/core/properties"
import {UIElementView} from "@bokehjs/models/ui/ui_element"
import {LayoutDOM} from "@bokehjs/models/layouts/layout_dom"

import {dict_to_records} from "./data"
Expand Down
4 changes: 3 additions & 1 deletion panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ export class DataTabulatorView extends HTMLBoxView {

const p = this.model.properties
const {configuration, layout, columns, groupby} = p;
this.on_change([configuration, layout, groupby], debounce(() => this.invalidate_render(), 20, false))
this.on_change([configuration, layout, groupby], debounce(() => {
this.invalidate_render()
}, 20, false))

this.on_change([columns], () => {
this.tabulator.setColumns(this.getColumns())
Expand Down
23 changes: 20 additions & 3 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1388,15 +1388,32 @@ def _get_model_children(self, panels, doc, root, parent, comm=None):
models[i] = model
return models

def _indexes_changed(self, old, new):
"""
Comparator that checks whether DataFrame indexes have changed.

If indexes and length are unchanged we assume we do not
have to reset various settings including expanded rows,
scroll position, pagination etc.
"""
if type(old) != type(new) or isinstance(new, dict):
return True
elif len(old) != len(new):
return False
return (old.index == new.index).all()

def _update_children(self, *events):
cleanup, reuse = set(), set()
page_events = ('page', 'page_size', 'value', 'pagination')
page_events = ('page', 'page_size', 'pagination')
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)
elif ((event.name in page_events and not self._updating) or
(self.pagination == 'remote' and event.name == 'sorters')):
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
Expand Down
Loading