|
@@ -1,7 +1,8 @@
|
|
|
-from typing import Dict, List
|
|
|
+from typing import Dict, List, Optional
|
|
|
|
|
|
from ..dependencies import register_component
|
|
|
from ..element import Element
|
|
|
+from ..functions.javascript import run_javascript
|
|
|
|
|
|
register_component('table', __file__, 'table.js', ['lib/ag-grid-community.min.js'])
|
|
|
|
|
@@ -41,3 +42,24 @@ class Table(Element):
|
|
|
:param args: arguments to pass to the method
|
|
|
"""
|
|
|
self.run_method('call_api_method', name, *args)
|
|
|
+
|
|
|
+ async def get_selected_rows(self) -> List[Dict]:
|
|
|
+ """Get the currently selected rows.
|
|
|
+
|
|
|
+ This method is especially useful when the table is configured with ``rowSelection: 'multiple'``.
|
|
|
+
|
|
|
+ See `AG Grid API <https://www.ag-grid.com/javascript-data-grid/row-selection/#reference-selection-getSelectedRows>`_ for more information.
|
|
|
+
|
|
|
+ :return: list of selected row data
|
|
|
+ """
|
|
|
+ return await run_javascript(f'return getElement({self.id}).gridOptions.api.getSelectedRows();')
|
|
|
+
|
|
|
+ async def get_selected_row(self) -> Optional[Dict]:
|
|
|
+ """Get the single currently selected row.
|
|
|
+
|
|
|
+ This method is especially useful when the table is configured with ``rowSelection: 'single'``.
|
|
|
+
|
|
|
+ :return: row data of the first selection if any row is selected, otherwise `None`
|
|
|
+ """
|
|
|
+ rows = await self.get_selected_rows()
|
|
|
+ return rows[0] if rows else None
|