Skip to content

Commit

Permalink
adding effect of selecting the table from the structure widget
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Jan 7, 2025
1 parent f9d5930 commit 7167a68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit 7167a68

Please sign in to comment.