Hi Guys, I am trying really simple example where in init phase I have following:
# Any code you write here will run when the form opens.
self.repeating_panel_1.item_template = 'ItemTemplate2'
test = ['test', 'test1', 'test2']
self.repeating_panel_1.items = test
print self.repeating_panel_1.items
RepeatingPanel itself contains text component and there are no data bindings (I try to get to point where I get selected rows from Google Sheet loaded, but so far I cannot load already pre-created simple list âtestâ.
Whatâs interesting, I can see same number of text_boxes within repeating panel as is number of elements in my list, but I am not able to actually show those values âtestâ, âtest1â, âtest2â (only 3 empty rows within RepeatingPanel).
I tried to compare to ToDo example app, but besides Data Bindings (which I donât use), I am not able to understand whatâs the difference.
See if you can work it out from this, if not post back here and Iâll see if I can help more.
Key points are :
Form1 sets an array of âmydata = valueâ pairs
I have bound the label in the ItemTemplate form to items[âmydataâ]
Anvil will auto-create a new ItemTemplate instance for each row of data in the items variable, and the data binding will ensure the label shows that data.
Just some extra points - whilst data binding in the IDE is convenient, you can also do it in code inside the itemtemplate form if you need to do more complex stuff like formatting or manipulation of the data. You could do this (in ItemTemplate1) remembering to remove the data binding in the IDE first :
The test variable you used doesnât have to be part of the form class (ie using âselfâ), so that wasnât wrong. Iâm sure itâs possible to pass just an array of values, but it would have required some code in the template form to display it i think, and I find it much more readable to explicitly specify the field:data pairings, especially once you get into multi-column itemtemplate forms.
I tried to iterate on your example and use google spreadsheet and this works for me:
self.ws = app_files.ao_craft_sheet[0]
#self.repeating_panel_1.items = self.ws.rows
l = []
for r in self.ws.rows:
l.append({'mydata': r['material']})
My question is if there is some more comfortable way how to get spreadsheet data into âdata-binding-friendlyâ format to display in repeating panel?
No, no. Itâs working, I was just wondering is simpler approach is possible (avoid âforâ cycle for example). I know that data tables have app_data.file.search() which can be used to populate the repeating panel list, maybe thereâs equivalent for google docs api.