I’ve searched the forum and can’t find any answer.
I want to display a list of employees and their departments (employee table linked to departement table). The linked column in data grid shows as <LiveObject: anvil.tables.Row> instead name of the department.
Table Employee
Name, Department
Table Department
Name, Description
My data grid source is this function: @anvil.server.callable
def get_employees():
return app_tables.employee.search()
I’m sure there is an easy way to do this, but I can’t find it,
Now, suppose on your form you have a DataGrid component with a repeating panel inside of it (this is a common set up). If you want to display the employees and their associated departments, you can set up the following data binding in the IDE (see @stefano.menci’s answer below to see how to do this in the code editor instead of the IDE):
Somewhere, perhaps in the data binding of the label that shows the department, you have something like self.item['department']. Try changing that to self.item['department']['name'].
But be careful: this will work with few employees, but if the number of lines increases you will have one round trip per line. It’s always a good idea to gather all the data on the server side in one round trip and return it at once.
How much is that number of line (hundreds or thousands)? And how would i gather all the data on the server side? I guess that would be in my get_employees function?