RowTemplate button click in first Data Grid can't load repeating_panel items in a second Grid on the same page

What I’m trying to do:
I have a Quote Grid which pops up all of the incomplete Quotes which need work. The user clicks on a button in the Quote Data Grid to select the quote to work on. This runs in the Quote Data Grid RowTemplate context. I successfully reach the Main Form (ProcessQuoteTemplate is the name) and I see the data for the Quote Items being fetched from debugging. However, the insertion into the repeating_panel for the Quote Items Data Grid fails.

The routine used to populate the Quote Items Data Grid is in the ProcessQuoteTemplate class. I’ve tested it and it works well, but only in that context.

What I’ve tried and what’s not working:
I’ve tried invoking the function this way as well:
ProcessQuoteComponent.load_quote_items_grid(ProcessQuoteComponent(), self.item[‘QuoteNum’])

The print() in load_quote_items_grid() retrieves the correct information from the DataTable every time. The issue is the Quote Items DataGrid does not get populated through the "repeating_panel_quote_items.items = " method

Code Sample:

  def button_select_click(self, **event_args):
    # load the specific quote's Quote Items
    #print(self.item['QuoteNum'])
    ProcessQuoteComponent().load_quote_items_grid(self.item['QuoteNum'])
    # then set Quote Item data grid to be visible.
    ProcessQuoteComponent().set_list_visible(True)

    # here is the load_quote_items_grid() function
      def load_quote_items_grid(self, qn):
    rows = anvil.server.call('any_items', qn)
    if rows:
      # select all of the Quote Item data columns into the panel, just skip the first column pointer
      preload = [ 
        { 
          'SKU': row['SKU'],
          'ManufNum': row['ManufNum'],
          'Qty': row['Qty'],
          'TargetPrice': row['TargetPrice'],
          'Description': row['Description'],
          'StygianCost': row['StygianCost'],
          'QuotePrice': row['QuotePrice'],
          'TaxRate': row['TaxRate'],
          'EstDelivery': row['EstDelivery']
        }
        for row in rows 
      ]
      print(preload)
      self.repeating_panel_quote_items.items = preload

Clone link:

Some more information in the form of what the GUI looks like: Concept is user clicks on the checkmark next to the desired Quote Number and the QuoteItems Data Grid will get populated with the available QuoteItem DataTable information. Ultimately user will populate all values and I’ll put a Submit button below the Quote Items Data Grid to do the rest of the workflow.

You’re running into the difference between a class and an instance of a class. ProcessQuoteComponent is a class. You create an instance of the class by following it with quotes.

The form that your repeating panel is on is an instance of the class. By using parentheses above, you’re creating a second instance, not modifying the original instance.

So in short, that’s the wrong way to do what you’re trying to do. The right way is for the repeating panel to communicate with the instance of the class that already exists, the instance that the repeating panel is in. That can be done with events.

Here’s an example app that shows the technique of communicating back to the parent form: Anvil | Login

1 Like

Yes, I knew it didn’t work, hence the post.

The idea is to register an event in the parent form and raise that event (with parameters) in the RowTemplate child, right? That makes sense. Then, I can grab the DataTable info and populate the second DataGrid from the parent context.

Thanks for the idea! I’ll get this implemented and confirm when it all works.

Yes, this worked well. Passing self.item through the event handler gets me the current Quotes row info in the context of the parent form. The Quote Detail form populates nicely, ready for editing.

Should have thought of event handlers… thanks for the prompt/tip!

1 Like