From 82893c384a732a81dda52e27452eaa96893db3ef Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 9 Jun 2026 11:30:53 +0200 Subject: [PATCH] split add_row_data into extend_row_data and insert_row_data --- stand/aggridx.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/stand/aggridx.py b/stand/aggridx.py index 74378cb..827925f 100644 --- a/stand/aggridx.py +++ b/stand/aggridx.py @@ -51,7 +51,7 @@ class aggridx(ui.aggrid): this operation maintains the current view on the data """ self.ensure_column_defs(row) - self.add_row_data([row]) + self.extend_row_data([row]) # def insert(self, index, row): # """ @@ -60,7 +60,7 @@ class aggridx(ui.aggrid): # this operation maintains the current view on the data # """ # self.ensure_column_defs(row) -# self.add_row_data([row], index=index) +# self.insert_row_data([row], index) # def extend(self, rows): # """ @@ -70,7 +70,7 @@ class aggridx(ui.aggrid): # """ # columns = dict.fromkeys(k for d in rows for k in d) # dict.fromkeys acts as ordered set # self.ensure_column_defs(columns) -# self.add_row_data(rows) +# self.extend_row_data(rows) def ensure_column_defs(self, columns): @@ -95,20 +95,32 @@ class aggridx(ui.aggrid): self.run_grid_method("setGridOption", "columnDefs", new_column_defs) - def add_row_data(self, rows, index=None): + def extend_row_data(self, rows): + """ + append rows to the bottom of the table + this operation maintains the current view on the data + """ + # update server without re-draw + with self.props.suspend_updates(): + self.options["rowData"].extend(rows) + + # update client + self.run_grid_method("applyTransaction", {"add": rows}) + + + def insert_row_data(self, rows, index): """ insert rows at the provided index, - with the default being appending at the bottom of the table this operation maintains the current view on the data """ row_data = self.options["rowData"] + if index is None or index < 0 or len(row_data) <= index: + raise IndexError(f"index {index} is out of range") + # update server without re-draw with self.props.suspend_updates(): - if index is not None and 0 <= index < len(row_data): - row_data[index:index] = rows - else: - row_data.extend(rows) + row_data[index:index] = rows # update client self.run_grid_method("applyTransaction", {"add": rows, "addIndex": index})