Skip to content

Commit

Permalink
TBR Removing DF breaks filter persistence on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed May 2, 2024
1 parent a3bf131 commit 4c39246
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions vizro-core/src/vizro/models/_components/ag_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@ def build(self):
Output(self._input_component_id, "className"),
Input("theme_selector", "checked"),
)

grid = self.__call__()
grid.rowData = []
return dcc.Loading(
[
html.H3(self.title, className="table-title") if self.title else None,
# The pagination setting (and potentially others) of the initially built AgGrid (in the build method
# here) must have the same setting as the object that is built by the on-page-load mechanism using
# with the user settings and rendered finally. Otherwise the grid is not rendered correctly.
# Hence be careful when editing the line below.
html.Div(self.__call__(), id=self.id, className="table-container"),
html.Div(grid, id=self.id, className="table-container"),
],
id=f"{self.id}_outer",
color="grey",
parent_className="loading-container",
)
)
18 changes: 12 additions & 6 deletions vizro-core/tests/unit/vizro/models/_components/test_ag_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ def test_ag_grid_build_mandatory_only(self, standard_ag_grid, gapminder):
ag_grid = vm.AgGrid(id="text_ag_grid", figure=standard_ag_grid)
ag_grid.pre_build()
ag_grid = ag_grid.build()
expected_ag_grid = dcc.Loading(
expected_ag_grid = dash_ag_grid(data_frame=gapminder, id="__input_text_ag_grid")()
expected_ag_grid.rowData = []
expected_build_result = dcc.Loading(
[
None,
html.Div(
dash_ag_grid(data_frame=gapminder, id="__input_text_ag_grid")(),
expected_ag_grid,
id="text_ag_grid",
className="table-container",
),
Expand All @@ -134,20 +136,24 @@ def test_ag_grid_build_mandatory_only(self, standard_ag_grid, gapminder):
parent_className="loading-container",
)

assert_component_equal(ag_grid, expected_ag_grid)
assert_component_equal(ag_grid, expected_build_result)

def test_ag_grid_build_with_underlying_id(self, ag_grid_with_id_and_conf, filter_interaction_action, gapminder):
ag_grid = vm.AgGrid(id="text_ag_grid", figure=ag_grid_with_id_and_conf, actions=[filter_interaction_action])
ag_grid.pre_build()
ag_grid = ag_grid.build()

expected_ag_grid = dash_ag_grid(
data_frame=gapminder, id="underlying_ag_grid_id",
)()
expected_ag_grid.rowData = []


expected_ag_grid = dcc.Loading(
[
None,
html.Div(
dash_ag_grid(
data_frame=gapminder, id="underlying_ag_grid_id", dashGridOptions={"pagination": True}
)(),
expected_ag_grid,
id="text_ag_grid",
className="table-container",
),
Expand Down
4 changes: 2 additions & 2 deletions vizro-core/tests/unit/vizro/tables/test_dash_ag_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def custom_ag_grid(data_frame):
[
None,
html.Div(
dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=row_data_date_raw),
dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=[]),
id=id,
className="table-container",
),
Expand Down Expand Up @@ -114,7 +114,7 @@ def custom_ag_grid(data_frame):
[
None,
html.Div(
dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=row_data_date_raw),
dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=[]),
id=id,
className="table-container",
),
Expand Down

0 comments on commit 4c39246

Please sign in to comment.