浏览代码

Demo to add new row

Rodja Trappe 2 年之前
父节点
当前提交
34fccd17fb
共有 1 个文件被更改,包括 18 次插入0 次删除
  1. 18 0
      website/more_documentation/table_documentation.py

+ 18 - 0
website/more_documentation/table_documentation.py

@@ -140,3 +140,21 @@ def more() -> None:
             columns=[{'name': col, 'label': col, 'field': col} for col in df.columns],
             rows=df.to_dict('records'),
         )
+
+    @text_demo('Adding Rows', '''
+        It's simple to add new rows with the `add_rows(dict)` method.
+    ''')
+    def adding_rows():
+        import os
+        import random
+
+        def add():
+            item = os.urandom(10 // 2).hex()
+            table.add_rows({'item_id': item, 'count': random.randint(0, 100)})
+
+        ui.button('add', on_click=add)
+        columns = [
+            {'name': 'item_id', 'label': 'Id', 'field': 'item_id'},
+            {'name': 'count', 'label': 'Count', 'field': 'count'},
+        ]
+        table = ui.table(columns=columns, rows=[], row_key='item_id').classes('w-full')