Hi Chris!
I’m-Stuck-Issue-1
To get the data into the Data Grid, you have probably done something like
self.repeating_panel_1.items = anvil.server.call('get_articles')
Each RowTemplate instance then automatically has an element of self.repeating_panel_1.items as its self.item. So, inside the RowTemplate's code, you can pass self.item into the new Form:
class RowTemplate1(RowTemplate1Template):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
# Any code you write here will run when the form opens.
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
open_form('Form2', article=self.item)
I’m-Stuck-Issue-2
Getting back to Form1 from Form2 could be as simple as:
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
open_form('Form1')
This will create a new instance of Form1 and display it on the page.
It sounds like you might want to keep the state of Form1 in memory and re-open the existing instance, so that changes to the page are remembered when you go back. In that case, you can create a Module to hold the global state and store the Form1 instance in that Module.
Let’s say you’ve called that Module State. When you’re setting up Form1, you can store a reference to the current instance in State:
import State
class Form1(Form1Template):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
State.form1_instance = self # Store the current Form1 instance for later
self.repeating_panel_1.items = anvil.server.call('get_articles')
Then you can get that instance out of State when you want to re-open the form:
import State
class Form2(Form2Template):
# ...
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
open_form(State.form1_instance)
Here’s a clone link for an example app that has a Data Grid full of article summaries, with links to a full article from each row of the Data Grid. There’s a link back to the article list page from the detail page. The article list page has a timer on it, that resumes from where it left off when you browse back to the page (to show that the state of the page has been remembered between visits).
https://anvil.works/ide#clone:WBLVN2MZZIJGGUVT=DEQYLFD5H624CX7K3EB3YZBN
Let me know if that solves your problems, and if I’ve made things clear enough!
Shaun