Using a DataGrid + Repeating Panel to Delete/Edit records

I’m having difficulty in communicating up and down the ‘stack’ of forms, etc. I have data grids with repeating panels, where I display contents of datatables. For CRUD operations, have the columns with links for delete and edit. Those work just fine, but I cannot figure out how to have those links’ code in the rowtemplate then trigger a refresh of the repeating panel in the parent form. I’ve read about creating custom events, but for the life of me I cannot figure this out.

The trick with custom events is getting a direct reference to the exact component (ancestor form) that will respond to them.

Finding the outermost form is easy: The top-level Form. So you could assign such a reference as a member of the outermost form’s tag member.

In general, these are some posts that I read for help dealing with “reaching back” and around with repeating panels.

Thanks folks - I’ll read up, test, and update on progress

My Publish-Subscribe Messaging library is another option.

1 Like

First: Thanks to all for suffering my stumbling through all of this.

I’ve explored the posts, documentation, etc., and while I better understand some things, I’m still vexed as to how to trigger a refresh of my repeating panel’s items. I believe it’s because I’m operating out of a form embedded in another form, hopefully this diag illustrates what I’m trying to accomplish. My app is too complex (I think) to simply post a clone link.

based on your component structure you could do

def delete_link_clicked(self, **event_args):
    self.parent.items = anvil.server.call_s('get_rows')

I’m always weary about getting too attached to parents though! (especially when you start using parent.parent)

The above code might mean you’ll end up writing the same anvil.server.call_s function more times than you would like.

you might generalise this with a custom event on the repeating panel

# inside SysAdminForm

def __init__(self, **properties):
    ...
    self.repeating_panel.set_event_handler('x-update', self.update)

def update(self, **event_args):
    self.repeating_panel.items = anvil.server.call_s('get_rows')

and then the delete click inside the RowPanel becomes

def delete_click(self, **event_args):
    self.parent.raise_event('x-update')

Once you realise you need to propagate events beyond a single parent then @owen.campbell’s subscriber library is a great dependency to look at!

you might also find this thread helpful

1 Like

I went with your first suggestion. If I ever get to a point when I’m not struggling against deadlines… I’ll explore the other options and suggestions, especially the messaging solution. As always, thanks so very much.