split add_row_data into extend_row_data and insert_row_data
This commit is contained in:
+21
-9
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user