For the native DataGrid component you’ll want to include an initial column.
Then add a checkbox component inside the RowTemplate
Assuming you want the action to get the selected rows on a button click
inside the main form you can do something like this
class Form1(Form1Template):
...
def get_selected_rows(self):
selected = []
for row_template in self.repeating_panel_1.get_components():
if row_template.check_box_1.checked:
selected.append(row_template.item)
return selected
def button_click(self, **event_args):
selected = self.get_selected_rows()
...
Note: the above will only get the selected items on the current page
If you want the selected items across all page you’d probably want the checkbox change event to communicate its state. (possibly by raising an event on the parent)
def check_box_change(self, **event_args):
self.parent.raise_event("x-selection-change", item=self.item, selected=self.check_box_1.checked)
and then in the main form
def __init__(self, **event_args):
self.repeating_panel_1.set_event_handler("x-selection-change", self.selection_change)
self.selected_items = set()
def selection_change(self, item, selected, **event_args):
"add or remove an item from the list of selected items"
if selected:
self.selected_items.add(item)
else:
self.selected_items.discard(item)
Also a tabulator version
You might also end up exploring the Tabulator dependency which might look something like this:
from tabulator.Tabulator import row_selection_column
class Form1(Form1Template):
def __init__(self, **properties):
...
self.tabulator_1.columns = [
row_selection_column,
{"title": "Name", "field": "name"},
...
]
self.tabulator_1.options = {
"app_table": app_tables.my_table,
"pagination": False,
"progressive_load": True,
"progressive_load_delay":200,
}
def get_selected_rows(self):
tabulator_rows = self.tabulator_1.get_selected_rows()
return [row.get_table_row() for row in tabulator_rows]
def button_click(self, **event_args):
selected = self.get_selected_rows()
...
clone:
https://anvil.works/build#clone:3ZT6VF4P3SOZJVO4=RYVPHN5QMWXAOVFQTI37LQP2