Hi all,
I know that a data grid is our most requested feature right now - and we’re working on it! However, in the meantime, let me show you just how much you can do with an Anvil custom component. In response to a question on another thread, I built a Custom HTML form that builds a table in HTML. Here it is (NB updated link):
It’s a custom component, and you use it like this:
self.table_1.columns = ["Name", "Age"]
self.table_1.data = [{'Name': 'Alice', 'Age': 2}, {'Name': 'Bob', 'Age': 8}]
And it looks like this:
You can also customise what appears in each cell. By default, it creates a Label, and sets its text
property by looking up the specified key in each row. But you can provide a function that returns any component you like! Eg, this code adds a “Delete” link to every row:
def mk_delete_link(row):
l = Link(icon="fa:times", text="Delete", foreground="red")
def del_row(**p):
self.table_1.data = [r for r in self.table_1.data if r != row]
l.set_event_handler('click', del_row)
return l
self.table_1.columns = [{'title': 'Name', 'key': 'Name'},
{'title': 'Age', 'key': 'Age'},
{'title': 'Delete', 'mk_component': mk_delete_link}]
It looks like this:
PS: Yes, this is a preview of what our data grid API might look like. Let us know how you get on!