I’m using the data grid and i’m trying to print a list of values in Separate rows
but Instead of that …it’s all printed in the first row
Code Sample:
@anvil.server.callable
def ReturnStatusOfID(id):
result = []
for row in data.itertuples():
if id== row.PT_NO:
result.append(row.RESULT)
return (result)
this is my function that return a list of values
example:
[1,0,1,0]
In your client snippet you are creating a list of one object (a dictionary) with two keys and assigning the list of values from the server to one of the keys, which is why you get all results displayed in one row.
If you want to keep the grid as it is, you will need to manufacture a list of objects, each having the id and one element of funA.
One way to do this is via a list comprehension e.g.
[{'column_1': id, 'column_2': elem} for elem in funA]
An alternative would be to build this list of dictionaries in the server function.
If i had another separated list that returned from another function (ex: the function is funB and it return [“A”,“B”,“C”,“D”]) and i want it to be in the dep column
the problem is when i assigned another value to repeating_panel_1, the values in the first one was deleted
self.repeating_panel_1.items =[{'column_1': id, 'column_2': elem} for elem in funA]
self.repeating_panel_1.items =[{ 'column_3': elem2} for elem in funB]
and doing nested loop doesn’t solve it correctly
self.repeating_panel_1.items =[{'column_1': id, 'column_2': elem,'column_3': elem2} for elem in funA for elem2 in funB]
Do the elements returned from funB correspond in any way to the elements from funA? If so, then you could combine the server functions into one and return a list of composite data. If not, then you should rethink how you display your data.
Each time you assign a list to items, it replaces the previous contents of items. Try building the entire list, with all desired modifications, separately. Verify that you have the list is correct, by printing it. Once it looks right, then assign it to items.
l=[funA,funB,funC]
# the len of each list must be the same.
self.repeating_panel_1.items =[{'column_1': mrn,'column_2': l[0][i],'column_3':l[1][i],'column_4':l[2][i]} for i in range(len(l[0]))]