-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
MWE
import numpy as np
import pandas as pd
from dash import Dash, Input, Output, callback, ctx, html
from dash_ag_grid import AgGrid
data = df = pd.DataFrame(
{
"id": range(1000),
"value": np.random.rand(1000),
}
)
clear_button = html.Button("Clear", id="clear")
reset_button = html.Button("Reset")
grid = AgGrid(
columnDefs=[
{"field": "id"},
{"field": "value"},
],
getRowId="params.data.id",
rowModelType="infinite",
)
@callback(
Output(grid, "getRowsResponse"),
Input(grid, "getRowsRequest"),
Input(clear_button, "n_clicks"),
Input(reset_button, "n_clicks"),
prevent_initial_call=True,
)
def update_rfq_grid_rows(
request,
n_clicks_clear,
n_clicks_reset,
):
if ctx.triggered_id == "clear":
response = {
"rowData": [],
"rowCount": 0,
}
print(response)
return response
if request is None:
partial_df = data.head(100)
else:
partial_df = data.iloc[request["startRow"] : request["endRow"]]
response = {
"rowData": partial_df.to_dict("records"),
"rowCount": len(data.index),
}
print(response)
return response
app = Dash()
app.layout = html.Div(
children=[
clear_button,
reset_button,
grid,
]
)
if __name__ == "__main__":
app.run(debug=True)What I do
- Run the app.
- Click the clear button.
- Click the reset button.
What I expect
After clicking the reset button, the grid should display data.
What I get
After clicking the reset button, the grid stays empty.
Why this is relevant
The two buttons mock my business logic. In my actual use case, the user can enter filter values into a form and click a button to filter the data in the grid. Some combinations of filter values are not fulfilled by any row in the dataset. As a result, the row response is empty. This is emulated by the clear button. Changing the filter settings should allow the user to fill the grid again with data. This is emulated by the reset button.
Environment
> pip freeze
blinker==1.9.0
certifi==2026.2.25
charset-normalizer==3.4.4
click==8.3.1
colorama==0.4.6
dash==4.0.0
dash_ag_grid==33.3.3
Flask==3.1.3
idna==3.11
importlib_metadata==8.7.1
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.3
narwhals==2.17.0
nest-asyncio==1.6.0
numpy==2.2.6
packaging==26.0
pandas==2.3.3
plotly==6.5.2
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.32.5
retrying==1.4.2
six==1.17.0
typing_extensions==4.15.0
tzdata==2025.3
urllib3==2.6.3
Werkzeug==3.1.6
zipp==3.23.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels