RepeatingPanel add_component method

The great thing about repeating panels:

set the items with a list of length n --> n item_templates appear with the item property set

The not so great thing about repeating panels:

If the list is long or the item_template has many data_bindings the form can take a long time to load

If the list changes, say by deleting an item or adding an item, then it can be a UI nightmare :smiling_imp: to have to repopulate the item_templates of a repeating_panel


deleting an item works well:

You don’t need to use repeatin_panel.items =
and so each item_template doesn’t have to be repopulated :trophy:
You can do something like…

# in the item_template form
def delete_button_click(self, **event_args):
  self.parent.raise_event('x-delete-item', item=self.item)
  self.remove_from_parent()
===================================================================================

# in the form with the repeating panel
def __init__(self, **properties):
  self.repeating_panel.set_event_handler('x-delete-item', self.delete_item)

def delete_item(self, item, **event_args):
  self.repeating_panel.items.remove(item)

adding an item isn’t so great

The only thing I can come up with is what has been suggested here by @daviesian :

Repeating panel to collect new information?

You have to repopulate all the item_templates in order to append a single item_template,
which can be slow.

def add_button_click(self, **event_args):
  self.repeating_panel.items = self.repeating_panel.items + [{'foo':'bar'}]


What if a repeating_panel had an add_component method:

add_component(item=)

To me, this makes sense since a repeating panel has an item_template so calling add_component would just add a new item_template with that item.

def add_button_click(self, **event_args):
  item = {'foo':'bar'}
  self.repeating_panel.items.append(item) 
  self.repeating_panel.add_component(item=item)

Not doing repeating_panel.items = means we don’t repopulate all the item_templates :boom:


Extension

If you know you have a long list of items you could populate some of the items in the init method and then the rest of the items in the form_show event

def __init__(self, items=None, **propeties):
  self.items = items
  self.repeating_panel.items = items[:3]


def form_show(self, **event_args):
  for item in self.items[3:]:
    self.repeating_panel.items.append(item)
    self.repeating_panel.add_component(item=item)
3 Likes

Isn’t that a column panel?

A ColumnPanel does the job… for sure

fake_repeating_panel = ColumnPanel()
fake_item_template = ItemTemplate

for item in items:
  fake_repeating_panel.add_component(fake_item_template(item=item))


But hey sometimes you want a RepeatingPanel

And I think there must be a better way to append an item to a repeating panel without having to repopulate all its item_templates

I sometimes use a timer instead of a loop to add an item every 0.01 seconds.

This gives the control back to the user while the list is still populating, so the user doesn’t need to wait for the whole list before starting to look and maybe click at the first items.

Then I add a little javascript that uses the scroll events to fetch another batch of items from the server and restart the timer, so I get a responsive and dynamic loading of large lists.

4 Likes

Nice … and it would be great to have the ability to use that approach with the RepeatingPanel too…

1 Like

I agree.
And with the DataGrid too.

Hey !

Having the same issue here.

Have you come with a solution? as I see the repeating panel object still does not have an add_component method.

How do you do the batching on the server side? Do you have a link to a post I can read. Tried searching. Thanks!

I will create a little sample app during the weekend and post a clone link.

1 Like

wow, really appreciate it :slight_smile:

Here it is: Auto Scroll - Automatically add content as the user scrolls the mouse wheel

2 Likes

Thank you very much! love the 2 for 1 lesson on auto scroll :slight_smile: