Ag_Grid - problem w row Transaction "remove"

Hi All,
I’ve a callback that refreshes my grid every few seconds.
I’ll do updates with rowTransactions.
and when I change values outside of the grid (on database side)
whenever I add record or change value in my db, the grid is being updated , but whenever I delete record from my db the grid doesn’t update with removing rows from the grid…strange thing cause df shows correct number of rows but grid not…
any idea what might cause this problem?
below my callback updating the grid…

@callback ( Output('grid-fakturowanie','rowTransaction', allow_duplicate=True),
                State('cell-editing', 'value')],
                  # State('grid-fakturowanie','selectedRows')],
                prevent_initial_call = True)

def update_grid (intervals,cellediting):
    if cellediting == "True":
        return dash.no_update
    conn = engine.connect()
    df_invoicing_updated = pd.read_sql_query(con=conn, sql=sql_query(query))
    for index, row in df_invoicing_updated.iterrows():
        if pd.isna(row['f_subtask_id']) or pd.isna(row['f_invoice_id']):
            subtask_id = row['invoice_subtask_id']
            invoice_id = row['origin_invoice_id']
            planned_value = row['planned_value']
            site = row['location']
            stmt = sql_query(
                f"set search_path to reporting; insert into fakturowanie (subtask_id,invoice_id,planned_value,site) values (:subtask_id,:invoice_id,:planned_value,:site)")
            print(f'{subtask_id},{invoice_id},{planned_value},{site} ')

            result = conn.execute(stmt,
                                  {'subtask_id': subtask_id, 'invoice_id': invoice_id, 'planned_value': planned_value,
                                   'site': site})
     df_invoicing_updated = pd.read_sql_query(con=conn, sql=sql_query(query))
    return( {'update': df_invoicing_updated.to_dict('records'),'remove': df_invoicing_updated.to_dict('records'),'add': df_invoicing_updated.to_dict('records')})

Hello @acidkans,

Not sure why you are trying to remove/update/add all the data each time.

If the data has unique identifiers, then you should be able to pass an update, and if things dont exist in the data anymore, then those should be removed, or if they were added, then they need to be added.

My assumption is that this essentially doubles the amount of rowData because you are adding and updating and the remove is only happening once.

1 Like

big misunderstanding, just thought that grid compares new df with old one and makes appropriate changes…now I know that I need to code separate logic for add, update, remove…

1 Like