Skip to content

Commit

Permalink
add get_selected_data (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrystalWindSnake authored Oct 21, 2024
1 parent 03e664a commit 80b288f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
54 changes: 54 additions & 0 deletions examples/pages/get_selected_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from nicegui_tabulator import tabulator
from nicegui import ui

tabledata = [
{
"id": 1,
"name": "Oli Bob",
"age": "12",
},
{
"id": 2,
"name": "Mary May",
"age": "1",
},
{
"id": 3,
"name": "Christine Lobowski",
"age": "42",
},
]

table_config = {
"height": 205,
"data": tabledata,
"rowHeader": {
"formatter": "rowSelection",
"titleFormatter": "rowSelection",
},
"columns": [
{
"title": "Name",
"field": "name",
},
{
"title": "Age",
"field": "age",
},
],
}


table = tabulator(table_config)


async def get_rows():
rows = await table.get_selected_data()
ui.notify(rows)


ui.button("Get Selected Rows", on_click=get_rows)


if __name__ in {"__main__", "__mp_main__"}:
ui.run()
4 changes: 4 additions & 0 deletions nicegui_tabulator/core/tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,7 @@ def print(
"""
self.sync_data_to_client()
self.run_table_method("print", row_range_lookup, style, config)

async def get_selected_data(self) -> List[Dict]:
"""Get the selected data from the table."""
return await self.run_table_method("getSelectedData")

0 comments on commit 80b288f

Please sign in to comment.