瀏覽代碼

add demo for `ui.aggrid` with complex objects

Falko Schindler 1 年之前
父節點
當前提交
3f4f2cff00
共有 1 個文件被更改,包括 18 次插入0 次删除
  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')