浏览代码

simplify table demo for showing/hiding columns

Falko Schindler 1 年之前
父节点
当前提交
ebcfebe58c
共有 1 个文件被更改,包括 2 次插入6 次删除
  1. 2 6
      website/more_documentation/table_documentation.py

+ 2 - 6
website/more_documentation/table_documentation.py

@@ -74,15 +74,11 @@ def more() -> None:
             {'name': 'Bob', 'age': 21},
             {'name': 'Carol'},
         ]
-        visible_columns = {column['name'] for column in columns}
         table = ui.table(columns=columns, rows=rows, row_key='name')
 
         def toggle(column: Dict, visible: bool) -> None:
-            if visible:
-                visible_columns.add(column['name'])
-            else:
-                visible_columns.remove(column['name'])
-            table._props['columns'] = [column for column in columns if column['name'] in visible_columns]
+            column['classes'] = '' if visible else 'hidden'
+            column['headerClasses'] = '' if visible else 'hidden'
             table.update()
 
         with ui.button(icon='menu'):