Skip to content

Commit

Permalink
followup aggrid state opti (#1125)
Browse files Browse the repository at this point in the history
* use on_mount to load df data

* fix some grids widths

* delay columns definitions
  • Loading branch information
Lendemor authored Dec 5, 2024
1 parent 30c5edb commit 2bb5864
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions docs/library/tables-and-data-grids/ag_grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,27 @@ import pandas as pd

class AgGridState(rx.State):
"""The app state."""
all_columns = [
ag_grid.column_def(field="country"),
ag_grid.column_def(field="pop"),
ag_grid.column_def(field="continent"),
ag_grid.column_def(field="lifeExp"),
ag_grid.column_def(field="gdpPercap"),
]

two_columns = [
ag_grid.column_def(field="country"),
ag_grid.column_def(field="pop"),
]
column_defs = all_columns
all_columns: list = []

two_columns: list = []
column_defs: list = all_columns
n_clicks = 0

@rx.event
def init_columns(self):
self.all_columns = [
ag_grid.column_def(field="country"),
ag_grid.column_def(field="pop"),
ag_grid.column_def(field="continent"),
ag_grid.column_def(field="lifeExp"),
ag_grid.column_def(field="gdpPercap"),
]
self.two_columns = [
ag_grid.column_def(field="country"),
ag_grid.column_def(field="pop"),
]
self.column_defs = self.all_columns

@rx.event
def update_columns(self):
self.n_clicks += 1
Expand All @@ -450,6 +456,7 @@ def ag_grid_simple_with_state():
id="ag_grid_basic_with_state",
row_data=df.to_dict("records"),
column_defs=AgGridState.column_defs,
on_mount=AgGridState.init_columns,
width="100%",
height="40vh",
),
Expand Down

0 comments on commit 2bb5864

Please sign in to comment.