Export ALL rows as CSV using Dash AG Grid + infinite scroll

Hi everyone!

Has anyone figured out how to export all rows of a table when that table is using Dash AG Grid with infinite scroll and pagination?

Right now, it’s only downloading the rows which I have loaded. E.g. if my entire table has 10,000 rows, but I’ve only loaded rows 0-99, my CSV only has 100 rows.

Example:

my_component = html.Div([
    html.Button(
        "Export to CSV",
        id="export_to_csv_btn",
    ),
    AgGrid(
        id="result-ag-grid-table",
        columnDefs=column_defs,
        columnSize="sizeToFit",
        rowModelType="infinite",
        dashGridOptions={
            "enableCellTextSelection": True,
            "domLayout": "autoHeight",
            "pagination": True,
            "paginationPageSize": 20,
        },
        style={"height": None, "overflowY": "auto", "overflowX": "auto"},
        dangerously_allow_code=True,
        csvExportParams={
            "fileName": f"{filename}.csv",
            "suppressQuotes": True,
        },
    )
])

@callback(
    Output("result-ag-grid-table", "getRowsResponse"),
    Input("result-ag-grid-table", "getRowsRequest"),
)
def fetch_rows(request):
    if not request:
        return no_update

    df, total_rows = sample_table_by_start_end_row(request["startRow"], request["endRow"])
    return {
        "rowCount": total_rows,
        "rowData": df.to_dict("records"),
    }

@callback(
    Output("result-ag-grid-table", "exportDataAsCsv"),
    Input(
        "export_to_csv_btn",
        "n_clicks",
    ),
    prevent_initial_call=True,
)
def export_to_csv(n_clicks):
    return bool(n_clicks)