What I’m trying to do:
I want to loop though all pages of the repeating panel and populate two list that I use for export in excel in CSV to do the search in data base.
While looping I gather 2 lists.
list of selected rows via Checkbox, selection on multiple pages
complete list of items from the repeating panel
Both lists I pass with Anvil Extras Messaging to other form where user can decide to export selected only or all.
With actual code I get the data from a single page only. I have like 100 of them.
def selecting_tool_export(self,**event_args):
"""export which rows were selected and all filtered for exporting tool"""
list_selected = []#list to gather selected unique ACNs
all_in_list = []#list to gather all filtered unique ACNs
for row_template in self.repeating_panel_assay.get_components():
all_in_list.append(row_template.item['application_code'])
if row_template.check_box_1.checked:#loop and gather numbers in list
list_selected.append(row_template.item['application_code'])#append the checked numbers
publisher.publish(channel="export_assay_unselected", title=all_in_list)#publish the data to popover_export
publisher.publish(channel="export_assay", title=list_selected)#publish the data to popover_export
Loop through repeating_panel_assay.items instead. Those are the data items. You are currently looping through UI elements, which are created as needed.
Thank you. I haven’t thought about it, but the 2nd If statent based on component checkbox won’t work.
Checkbox is not a part of the items. How to fix that problem?
def selecting_tool_export(self,**event_args):
"""export which rows were selected and all filtered for exporting tool"""
list_selected = []#list to gather selected unique ACNs
all_in_list = []#list to gather all filtered unique ACNs
for values in self.repeating_panel_assay.items:
all_in_list.append(values)
if self.check_box_1.checked:#loop and gather numbers in list
list_selected.append(values)#append the checked numbers
publisher.publish(channel="export_assay_unselected", title=all_in_list)#publish the data to popover_export
publisher.publish(channel="export_assay", title=list_selected)#publish the data to popover_export
Presumably you have something in the dictionary that represents an item that mirrors that checkbox. You can look at that value instead of looking at the checkbox.
There are more specifics, but they depend on whether your repeating panel items are straight dictionaries, whether they’re data table rows, what the checkboxes represent, how you’re using the checkbox values, etc. More detail would be needed to offer more specific advice.
I did what you proposed, extracted one row of my data table from the Data Grid items.
Checkbox is just an object, located in each row with no value representation attached in .items .
I made my row clickable with Envil Augment and by clicking it the value changes to True. So you can select multiple rows in different pages and do some actions with the selected rows.
Looping with self.repeating_panel_assay.get_components(): gives me the required results, but only for the actually loaded row. It is possible to let it loop everything?
The way I’d approach that is to let the enclosing form keep track of the selected items (the actual self.item from the repeating panel row template). Then you can do whatever you want with them wherever you want, no need to loop over anything. Your augment click can add/remove the selection status of the clicked item using events.
You seem to have an UI based approach. You have UI components talking to each other. One UI component asks the other UI component “tell me what you know”.
I like a data based approach, where all the forms deal with the same data set. They show the data and they tell the data about any user interaction, like a click on a checkbox. The UI components show and interact with the data, not with other UI components.
This way not only can you know about the status of your objects more easily, you can also change your UI components, remove or add forms and nothing breaks.
In your case, knowing very little about your implementation, I would have the checkbox events add the checked info to the data. Perhaps your data is a table row and you don’t have that “checked” column in the table, but you can still add it to it from code. Then, any other UI component could check whether “checked” has been added or not and what is its value.
In my more complex apps I create a class that holds the row in a member and adds any other feature, like your “checked” or “selected” properties, that does not exist in the table. In simpler apps I just add it to the row object.
In this post I describe this technique (and more). It is not a post for beginners and I don’t know your Python skill level. You can give it a try and see if it helps. (I know, you asked for a simple “how do I do this little thing” and here I am telling you to redesign your whole app… I just hope it helps, maybe on your next app ).
Thanks for help. @stefano.menci your approach is really good. Maybe I will have to redesign everything
For now I did something else. To keep the track in the form. I just made a global list that is being appended or removed everytime the row is clicked. It should do the trick for now. I will consider redesigning everything.