Hi! I’m using Dash AG Grid with Infinite Scroll & pagination. I have some complex sort/filter options, so I have a separate component. What I have working correctly right now is:
- Pick some sort/filter options in the custom component
- Click “sort” button
- Update
getRowsResponse
with newrowData
, which correctly returns the sorted data for the block size (100 rows)
The bug:
4. Scroll through the pages until Dash fetches another block of data, e.g. rows 100 - 200
5. The Dash AG Grid correctly fetches the next 100 rows of data
6. Change sort/filter options
7. Rows 100-200 are correct, but rows 1 - 100 are incorrect, because The AG Grid is using the cached blocks from the first sort
I’ve also tried to generate an entirely new AG Grid table each time a custom sort/filter is entered in, but since it has the same component ID, I think Dash isn’t properly updating the previous component with the new component.
Is there a way to “force” Dash AG Grid to fetch each block? Or an alternative that I’m missing?
Pseudocode:
# Generate the container component, including the table and misc related components
@callback(
Output({"type": IDs.TABLE_CONTAINER, "index": MATCH}, "children"),
Input({"type": IDs.TABLE_CONTAINER, "index": MATCH}, "children")
)
def generate_table(children):
...
table = AgGrid(
id={"type": IDs.TABLE, "index": MATCH},
"rowModelType": "infinite",
"rowData": data.to_dict("records"),
"columnDefs": column_defs,
...
)
return [
component_1,
table,
]
@callback(
Output({"type": IDs.TABLE, "index": MATCH}, "getRowsResponse"),
Input({"type": IDs.TABLE, "index": MATCH}, "getRowsRequest"),
Input({"type": IDs.SORT_TABLE_BUTTON, "index": MATCH}, "n_clicks"),
# Various user inputs to sort/filter by, etc.
State({"type": "sort-input-1", "index": MATCH}, "value"),
State({"type": "sort-input-2", "index": MATCH}, "value"),
State({"type": "sort-input-3", "index": MATCH}, "value"),
# more states below, etc.
)
def sort_table(get_rows_request, n_clicks, value_1, value_2, value_3):
...
table_fetch_params = { ... }
sorted_data, total_row_count = fetch_data(table_fetch_params, value_1, value_2, value_3)
return {
"rowData": sorted_data.to_dict("records"),
"rowCount": total_row_count,
}