Skip to content

Commit

Permalink
Merge pull request #154 from maxfordham/reselect-after-save
Browse files Browse the repository at this point in the history
🚑 🐛 Reselect selection after editing instance
  • Loading branch information
jgunstone authored Apr 14, 2023
2 parents 956358c + 15605f6 commit 7c1ce5a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/ipyautoui/custom/editgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# format_version: '1.5'
# jupytext_version: 1.14.5
# kernelspec:
# display_name: Python 3.9 (XPython)
# display_name: Python 3 (ipykernel)
# language: python
# name: xpython
# name: python3
# ---

# +
Expand Down Expand Up @@ -445,15 +445,20 @@ def _validate_edit_click(self):
self._check_one_row_selected()

def _save_edit_to_grid(self):
selections = self.grid.selections # Store current selection
self.grid.selections = []
# ^ HOTFIX: Have to set empty to reselect later on

if self.datahandler is not None:
self._reload_all_data()
else:
changes = self.grid.set_item_value(
self.grid.selected_index, self.ui_edit.value
)
self.grid.set_item_value(self.grid.selected_index, self.ui_edit.value)

if self.close_crud_dialogue_on_action:
self.buttonbar_grid.edit.value = False
else:
# Reselect previous selection after reload.
self.grid.selections = selections

def _set_ui_edit_to_selected_row(self):
self.ui_edit.value = self.grid.selected
Expand Down Expand Up @@ -660,10 +665,12 @@ class TestDataFrame(BaseModel):


if __name__ == "__main__":
import random

datahandler = DataHandler(
fn_get_all_data=lambda: AUTO_GRID_DEFAULT_VALUE * random.randint(1, 10),
fn_get_all_data=lambda: AUTO_GRID_DEFAULT_VALUE * random.randint(1, 5),
fn_post=lambda v: print(v),
fn_patch=lambda v: print(v),
fn_patch=lambda v: v,
fn_delete=lambda v: print(v),
fn_copy=lambda v: print(v),
)
Expand Down

0 comments on commit 7c1ce5a

Please sign in to comment.