So it seems something is going wrong during the hydration process of the virtualRowData.
During componentDidUpdate() the filterChange is called with: this.onFilterChanged(true);
It gets and empty filter dict from the const filterModel = this.state.gridApi.getFilterModel();
and pass that over the prefilled I had.
After some more testing with a smaller dataset, I think it’s the combination of updating the row data in a callback and persisting the filter.
If you pass in the below example the row data directly, the behaviour is as expected. If you uncomment the callback and use that to update, then it resets like I had before.
import dash
import dash_ag_grid as dag
from dash import Dash, Input, Output, dcc, html, callback
app = Dash(__name__)
columnDefs = [
{
"field": "asx_code",
"headerName": "ASX Code",
"editable": False,
},
{
"field": "company_name",
"headerName": "Company Name",
"editable": False,
},
{
"field": "industry",
"headerName": "Industry",
"editable": False,
},
{
"field": "anomaly_score",
"headerName": "Anomaly Score",
"filter": "agNumberColumnFilter",
"editable": False,
"valueFormatter": {"function": "d3.format('.2f')(params.value)"},
},
{
"field": "alerts",
"headerName": "Alerts",
"editable": False,
},
]
rowData = [
{
"asx_code": "LEG",
"company_name": "Legend Mining Ltd",
"logo_code": [
"LEG",
"https://s3-ap-southeast-2.amazonaws.com/dhi-disclosures-public-dev/company_logo/LEG.ico",
],
"industry": "Materials",
"anomaly_score": 10.94,
"alerts": 10,
},
{
"asx_code": "KNI",
"company_name": "KUNIKO LIMITED",
"logo_code": ["KNI", None],
"industry": "Materials",
"anomaly_score": 6.98,
"alerts": 0,
},
{
"asx_code": "SPQ",
"company_name": "Superior Resources Ltd",
"logo_code": [
"SPQ",
"https://s3-ap-southeast-2.amazonaws.com/dhi-disclosures-public-dev/company_logo/SPQ.ico",
],
"industry": "Materials",
"anomaly_score": 9.39,
"alerts": 0,
},
{
"asx_code": "SER",
"company_name": "Strategic Energy Resources Ltd",
"logo_code": [
"SER",
"https://s3-ap-southeast-2.amazonaws.com/dhi-disclosures-public-dev/company_logo/SER.ico",
],
"industry": "Materials",
"anomaly_score": 8.04,
"alerts": 0,
},
{
"asx_code": "NWM",
"company_name": "Norwest Minerals Ltd",
"logo_code": ["NWM", None],
"industry": "Materials",
"anomaly_score": 12.05,
"alerts": 0,
},
]
app.layout = html.Div(
[
dcc.Markdown("Use the 'Update Filter' button to set the `filterModel` "),
html.Button("Update Filter", id="filter-model-btn", n_clicks=0),
dag.AgGrid(
id="filter-model-grid1",
columnSize="sizeToFit",
columnDefs=columnDefs,
rowData=rowData,
defaultColDef={"filter": True, "floatingFilter": True},
persistence=True,
persisted_props=["filterModel"],
dashGridOptions={"animateRows": False},
),
]
)
# @callback(
# Output("filter-model-grid1", "rowData"),
# Input("filter-model-grid1", "id"),
# )
# def update_row_data(trigger):
# return rowData
if __name__ == "__main__":
app.run(debug=True)
Probably the push of the new rowData resets the filter.