diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py index d72a0d037..9b25f5415 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/structure.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/structure.py @@ -93,3 +93,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 diff --git a/src/aiidalab_qe/common/widgets.py b/src/aiidalab_qe/common/widgets.py index a93d633c7..b4ced2f87 100644 --- a/src/aiidalab_qe/common/widgets.py +++ b/src/aiidalab_qe/common/widgets.py @@ -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 };