Skip to content

Commit 72911d9

Browse files
adding effect of selecting the table from the structure widget (#1061)
1 parent f9d5930 commit 72911d9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/aiidalab_qe/app/result/components/viewer/structure/structure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def _render(self):
3232
self.atom_coordinates_table,
3333
]
3434
self.atom_coordinates_table.observe(self._change_selection, "selected_rows")
35+
# Listen for changes in self.widget.displayed_selection and update the table
36+
self.widget.observe(self._update_table_selection, "displayed_selection")
3537

3638
# HACK to resize the NGL viewer in cases where it auto-rendered when its
3739
# container was not displayed, which leads to a null width. This hack restores
@@ -66,3 +68,7 @@ def _generate_table(self, structure):
6668
def _change_selection(self, _):
6769
selected_indices = self.atom_coordinates_table.selected_rows
6870
self.widget.displayed_selection = selected_indices
71+
72+
def _update_table_selection(self, change):
73+
selected_indices = change.new
74+
self.atom_coordinates_table.selected_rows = selected_indices

src/aiidalab_qe/common/widgets.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,20 @@ class TableWidget(anywidget.AnyWidget):
12821282
12831283
drawTable();
12841284
model.on("change:data", drawTable);
1285+
model.on("change:selected_rows", (e) => {
1286+
const newSelection = model.get("selected_rows");
1287+
// Update row selection based on selected_rows
1288+
const rows = domElement.querySelectorAll('tr');
1289+
rows.forEach((row, index) => {
1290+
if (index > 0) {
1291+
if (newSelection.includes(index - 1)) {
1292+
row.classList.add('selected-row');
1293+
} else {
1294+
row.classList.remove('selected-row');
1295+
}
1296+
}
1297+
});
1298+
});
12851299
el.appendChild(domElement);
12861300
}
12871301
export default { render };

0 commit comments

Comments
 (0)