@@ -45,9 +45,9 @@ The format of the data passed to the `row_data` prop is a list of dictionaries.
4545
4646``` python
4747[
48- \ {"direction": "N", "strength": "0-1", "frequency": 0.5\ },
49- \ {"direction": "NNE", "strength": "0-1", "frequency": 0.6\ },
50- \ {"direction": "NE", "strength": "0-1", "frequency": 0.5\ },
48+ {" direction" : " N" , " strength" : " 0-1" , " frequency" : 0.5 },
49+ {" direction" : " NNE" , " strength" : " 0-1" , " frequency" : 0.6 },
50+ {" direction" : " NE" , " strength" : " 0-1" , " frequency" : 0.5 },
5151]
5252```
5353
@@ -257,6 +257,7 @@ import reflex as rx
257257import reflex_enterprise as rxe
258258import pandas as pd
259259
260+
260261class AGGridEditingState (rx .State ):
261262 data: list[dict ] = []
262263 _data_df: pd.DataFrame
@@ -270,15 +271,30 @@ class AGGridEditingState(rx.State):
270271 def cell_value_changed (self , row , col_field , new_value ):
271272 self ._data_df.at[row, col_field] = new_value
272273 self .data = self ._data_df.to_dict(" records" )
273- yield rx.toast(f " Cell value changed, Row: { row} , Column: { col_field} , New Value: { new_value} " )
274+ yield rx.toast(
275+ f " Cell value changed, Row: { row} , Column: { col_field} , New Value: { new_value} "
276+ )
274277
275278
276279column_defs = [
277- \{"field": "country"\},
278- \{"field": "pop", "headerName": "Population", "editable": True, "cellEditor": rxe.ag_grid.editors.number\},
279- \{"field": "continent", "editable": True, "cellEditor": rxe.ag_grid.editors.select, "cellEditorParams": \{"values": ['Asia', 'Europe', 'Africa', 'Americas', 'Oceania']\}\},
280+ {" field" : " country" },
281+ {
282+ " field" : " pop" ,
283+ " headerName" : " Population" ,
284+ " editable" : True ,
285+ " cellEditor" : rxe.ag_grid.editors.number,
286+ },
287+ {
288+ " field" : " continent" ,
289+ " editable" : True ,
290+ " cellEditor" : rxe.ag_grid.editors.select,
291+ " cellEditorParams" : {
292+ " values" : [" Asia" , " Europe" , " Africa" , " Americas" , " Oceania" ]
293+ },
294+ },
280295]
281296
297+
282298def ag_grid_simple_editing ():
283299 return rxe.ag_grid(
284300 id = " ag_grid_basic_editing" ,
@@ -336,6 +352,7 @@ import reflex as rx
336352import reflex_enterprise as rxe
337353import pandas as pd
338354
355+
339356class AGGridState2 (rx .State ):
340357 data: list[dict ] = []
341358
@@ -344,12 +361,14 @@ class AGGridState2(rx.State):
344361 _df = pd.read_csv(" data/gapminder2007.csv" )
345362 self .data = _df.to_dict(" records" )
346363
364+
347365column_defs = [
348- \ {"field": "country"\ },
349- \ {"field": "pop", "headerName": "Population"\ },
350- \ {"field": "continent"\ },
366+ {" field" : " country" },
367+ {" field" : " pop" , " headerName" : " Population" },
368+ {" field" : " continent" },
351369]
352370
371+
353372def ag_grid_state_2 ():
354373 return rxe.ag_grid(
355374 id = " ag_grid_state_2" ,
@@ -370,8 +389,10 @@ import reflex as rx
370389import reflex_enterprise as rxe
371390import pandas as pd
372391
392+
373393class AgGridState (rx .State ):
374394 """ The app state."""
395+
375396 all_columns: list = []
376397
377398 two_columns: list = []
@@ -381,15 +402,15 @@ class AgGridState(rx.State):
381402 @rx.event
382403 def init_columns (self ):
383404 self .all_columns = [
384- \ {"field": "country"\ },
385- \ {"field": "pop"\ },
386- \ {"field": "continent"\ },
387- \ {"field": "lifeExp"\ },
388- \ {"field": "gdpPercap"\ },
405+ {" field" : " country" },
406+ {" field" : " pop" },
407+ {" field" : " continent" },
408+ {" field" : " lifeExp" },
409+ {" field" : " gdpPercap" },
389410 ]
390411 self .two_columns = [
391- \ {"field": "country"\ },
392- \ {"field": "pop"\ },
412+ {" field" : " country" },
413+ {" field" : " pop" },
393414 ]
394415 self .column_defs = self .all_columns
395416
@@ -436,14 +457,14 @@ import reflex_enterprise as rxe
436457import pandas as pd
437458from sqlmodel import select
438459
460+
439461class Country (rx .Model , table = True ):
440462 country: str
441463 population: int
442464 continent: str
443465
444466
445467class AGGridDatabaseState (rx .State ):
446-
447468 countries: list[Country]
448469
449470 # Insert data from a csv loaded dataframe to the database (Do this on the page load)
@@ -453,9 +474,9 @@ class AGGridDatabaseState(rx.State):
453474 with rx.session() as session:
454475 for _, row in data.iterrows():
455476 db_record = Country(
456- country = row[' country' ],
457- population = row[' pop' ],
458- continent = row[' continent' ],
477+ country = row[" country" ],
478+ population = row[" pop" ],
479+ continent = row[" continent" ],
459480 )
460481 session.add(db_record)
461482 session.commit()
@@ -476,15 +497,30 @@ class AGGridDatabaseState(rx.State):
476497 country = Country(** self .countries[row])
477498 session.merge(country)
478499 session.commit()
479- yield rx.toast(f " Cell value changed, Row: \ { row} , Column: \ { col_field} , New Value: \ { new_value} " )
500+ yield rx.toast(
501+ f " Cell value changed, Row: { row} , Column: { col_field} , New Value: { new_value} "
502+ )
480503
481504
482505column_defs = [
483- \{"field": "country"\},
484- \{"field": "population", "headerName": "Population", "editable": True, "cellEditor": rxe.ag_grid.editors.number\},
485- \{"field": "continent", "editable": True, "cellEditor": rxe.ag_grid.editors.select, "cellEditorParams": \{"values": ['Asia', 'Europe', 'Africa', 'Americas', 'Oceania']\}\},
506+ {" field" : " country" },
507+ {
508+ " field" : " population" ,
509+ " headerName" : " Population" ,
510+ " editable" : True ,
511+ " cellEditor" : rxe.ag_grid.editors.number,
512+ },
513+ {
514+ " field" : " continent" ,
515+ " editable" : True ,
516+ " cellEditor" : rxe.ag_grid.editors.select,
517+ " cellEditorParams" : {
518+ " values" : [" Asia" , " Europe" , " Africa" , " Americas" , " Oceania" ]
519+ },
520+ },
486521]
487522
523+
488524def index ():
489525 return rxe.ag_grid(
490526 id = " ag_grid_basic_editing" ,
@@ -495,6 +531,7 @@ def index():
495531 height = " 40vh" ,
496532 )
497533
534+
498535# Add state and page to the app.
499536app = rx.App()
500537app.add_page(index, on_load = AGGridDatabaseState.insert_dataframe_to_db)
@@ -657,9 +694,9 @@ df = pd.read_csv(
657694)
658695
659696column_defs = [
660- \ {"field": "country", "checkboxSelection": True\ },
661- \ {"field": "pop"\ },
662- \ {"field": "continent"\ },
697+ {" field" : " country" , " checkboxSelection" : True },
698+ {" field" : " pop" },
699+ {" field" : " continent" },
663700]
664701
665702def ag_grid_api_argument ():
0 commit comments