table.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Dict, List
  2. from ..dependencies import register_component
  3. from ..element import Element
  4. register_component('table', __file__, 'table.js', ['lib/ag-grid-community.min.js'])
  5. class Table(Element):
  6. def __init__(self, options: Dict, *, html_columns: List[int] = [], theme: str = 'balham') -> None:
  7. """Table
  8. An element to create a table using `AG Grid <https://www.ag-grid.com/>`_.
  9. :param options: dictionary of AG Grid options
  10. :param html_columns: list of columns that should be rendered as HTML (default: `[]`)
  11. :param theme: AG Grid theme (default: 'balham')
  12. """
  13. super().__init__('table')
  14. self._props['options'] = options
  15. self._props['html_columns'] = html_columns
  16. self._classes = [f'ag-theme-{theme}', 'w-full', 'h-64']
  17. @property
  18. def options(self) -> Dict:
  19. return self._props['options']
  20. def update(self) -> None:
  21. super().update()
  22. self.run_method('update_grid')
  23. def call_api_method(self, name: str, *args) -> None:
  24. self.run_method('call_api_method', name, args)