Skip to content

filterModel is not persisted when grid is initialized with empty rowData #430

@tlauli

Description

@tlauli

Describe your context

dash                                3.3.0
dash_ag_grid                        32.3.4

Describe the bug

When grid is initialized with empty rowData (which are later filled in through a callback) and a persisted filterModel prop, the persisted prop is cleared.

Expected behavior
The filterModel prop is used and not cleared.

MWE
Run the following snippet, click the Add data button and set a filter on the text column. Refresh the page. Observe that the filter is no longer set. In case the rowData is not empty, everything works as expected and the filter is set after the page is refreshed.

import dash_ag_grid as dag
from dash import Dash, Input, Output, callback, html

layout = [
    dag.AgGrid(
        id="ag-grid",
        rowData=[
            # {"number": 1, "text": "a"},
        ],
        columnDefs=[
            {"field": "number", "filter": "agNumberColumnFilter"},
            {"field": "text", "filter": "agTextColumnFilter"},
        ],
        persistence=True,
        persisted_props=["filterModel"],
    ),
    html.Button(
        "Add data",
        id="button",
    ),
]


@callback(
    Output("ag-grid", "rowData"),
    Input("button", "n_clicks"),
    prevent_initial_call=True,
)
def add_data(_):
    return [
        {"number": 1, "text": "a"},
        {"number": 2, "text": "b"},
    ]


app = Dash(__name__)
app.layout = layout
app.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions