Sfoglia il codice sorgente

add demo for `ui.aggrid` with complex objects

Falko Schindler 1 anno fa
parent
commit
3f4f2cff00
1 ha cambiato i file con 18 aggiunte e 0 eliminazioni
  1. 18 0
      website/more_documentation/aggrid_documentation.py

+ 18 - 0
website/more_documentation/aggrid_documentation.py

@@ -154,3 +154,21 @@ def more() -> None:
                 {'name': 'Carol', 'age': 42},
             ],
         }).on('cellClicked', lambda event: ui.notify(f'Cell value: {event.args["value"]}'))
+
+    @text_demo('AG Grid with complex objects', '''
+        You can use nested complex objects in AG Grid by separating the field names with a period.
+        (This is the reason why keys in `rowData` are not allowed to contain periods.)
+    ''')
+    def aggrid_with_complex_objects():
+        ui.aggrid({
+            'columnDefs': [
+                {'headerName': 'First name', 'field': 'name.first'},
+                {'headerName': 'Last name', 'field': 'name.last'},
+                {'headerName': 'Age', 'field': 'age'}
+            ],
+            'rowData': [
+                {'name': {'first': 'Alice', 'last': 'Adams'}, 'age': 18},
+                {'name': {'first': 'Bob', 'last': 'Brown'}, 'age': 21},
+                {'name': {'first': 'Carol', 'last': 'Clark'}, 'age': 42},
+            ],
+        }).classes('max-h-40')