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),
[Input('interval-refresh-invoicing','n_intervals'),
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})
conn.commit()
df_invoicing_updated = pd.read_sql_query(con=conn, sql=sql_query(query))
conn.close()
return( {'update': df_invoicing_updated.to_dict('records'),'remove': df_invoicing_updated.to_dict('records'),'add': df_invoicing_updated.to_dict('records')})