main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. from nicegui import ui
  3. class Demo:
  4. filter = ''
  5. fields = [
  6. {'name': 'name', 'label': 'Name', 'field': 'name', 'required': True},
  7. {'name': 'age', 'label': 'Age', 'field': 'age', 'sortable': True},
  8. ]
  9. data = [
  10. {'name': 'Alice', 'age': 18},
  11. {'name': 'Bob', 'age': 21},
  12. {'name': 'Carol'},
  13. ]
  14. with ui.qtable(title='QTable', columns=Demo.fields, rows=Demo.data, key='name', selection='single') \
  15. .bind_value(Demo, 'filter') as table:
  16. with table.add_slot('top-right'):
  17. with ui.input(placeholder='Search').props('type="search"').bind_value(Demo, 'filter') as search:
  18. with search.add_slot('append'):
  19. ui.icon('search')
  20. with table.add_slot('top-row'):
  21. with table.row():
  22. with table.cell().props('colspan="100%"'):
  23. ui.label('This is a top row').classes('text-center')
  24. with table.add_slot('bottom-row'):
  25. with table.row():
  26. with table.cell().props('colspan="100%"'):
  27. ui.label('This is a bottom row').classes('text-center')
  28. with table.add_slot('bottom'):
  29. ui.label('Bottom slot')
  30. ui.label('').bind_text_from(table, 'selected', lambda val: f'Current selection: {val.__repr__()}')
  31. ui.run()