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

Adding effect of selecting the table from the structure widget #1061

Merged
merged 1 commit into from
Jan 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def _render(self):
self.atom_coordinates_table,
]
self.atom_coordinates_table.observe(self._change_selection, "selected_rows")
# Listen for changes in self.widget.displayed_selection and update the table
self.widget.observe(self._update_table_selection, "displayed_selection")

# HACK to resize the NGL viewer in cases where it auto-rendered when its
# container was not displayed, which leads to a null width. This hack restores
Expand Down Expand Up @@ -66,3 +68,7 @@ def _generate_table(self, structure):
def _change_selection(self, _):
selected_indices = self.atom_coordinates_table.selected_rows
self.widget.displayed_selection = selected_indices

def _update_table_selection(self, change):
selected_indices = change.new
self.atom_coordinates_table.selected_rows = selected_indices
14 changes: 14 additions & 0 deletions src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,20 @@ class TableWidget(anywidget.AnyWidget):

drawTable();
model.on("change:data", drawTable);
model.on("change:selected_rows", (e) => {
const newSelection = model.get("selected_rows");
// Update row selection based on selected_rows
const rows = domElement.querySelectorAll('tr');
rows.forEach((row, index) => {
if (index > 0) {
if (newSelection.includes(index - 1)) {
row.classList.add('selected-row');
} else {
row.classList.remove('selected-row');
}
}
});
});
el.appendChild(domElement);
}
export default { render };
Expand Down
Loading