What I’m trying to do: I’d like to find an anvil app that lets you edit all your database tables/records. Sort of an admin type interface I guess you would call it.
What I’ve tried and what’s not working:
Creating the editor from scratch is so tedious. It seems there should be some framwork that has this functionality built in.
The general approach was to subclass from DataGrid and to override the ItemTemplate of the RepeatingPanel that was added to the DataGrid.
It also assumes that the Table permissions are set such that they are editable from client code.
You could extend the clone above to be more bespoke depending on your requirements.
Some code:
class TableEditor(DataGrid):
def __init__(self, table, **properties):
columns = filter(lambda d: not d['type'].startswith('live'),
table.list_columns()) # ignore live object columns
columns = [{'id': get_id(), # random string
'title': c['name'].capitalize(),
'data_key': c['name'],
'type': c['type']
}
for c in columns
]
super().__init__(auto_header=True,
columns=columns,
rows_per_page=10,
show_page_controls=True,
**properties)
def item_template(item, **properties):
drp = DataRowPanel(item=item,
auto_display_data=False,
**properties)
for column in columns:
c = get_component(item, column)
# get the component based on the column type
if c is not None:
drp.add_component(c, column=column['id'])
return drp
rp = RepeatingPanel(item_template=item_template)
self.add_component(rp)
rp.items = table.search()