I am searching data from table and displaying them in a repeating panel. The rows are listed by last entry date.
I do not want to display all the rows in the repeating panel, but only some rows (exp. the first six rows displayed).
In my case I can’t add a page number because I want to sum values for these 6 rows and not for all the rows in the repeating panel.
Is possible to define how many rows to display in the repeating panel?
Code Sample:
# code snippet
def search(self, **event_args):
self.repeating_panel_2020.items = anvil.server.call('search7',self.text_box_1.text)
@anvil.server.callable
def search7(query):
result = app_tables.register_2020.search(tables.order_by('data',ascending=False))
if query:
result = [
x for x in result
if query in x['name']
or query in x['id']
]
return result
I tried to add [0:5] but the repeating panel is not showing anything
Just to illustrate what I am trying to do:
from the table below I search by column ‘Name’ - Besar and I want to display in the repeating panel only the first five rows.
result = app_tables.register_2020.search(tables.order_by(‘data’,ascending=False))[:5]
print(result)
<anvil._server.LiveObjectProxy.Iter object at 0x000000000226ac60>
if I run:
result = app_tables.register_2020.search(tables.order_by(‘data’,ascending=False))[5]
<LiveObject: anvil.tables.Row>
TypeError: list indices must be integers or slices, not str at [ServerModule7, line 15]
I see your clone, but I want to search through the table and then on the result display some rows not all. In your example you just display the first two rows.
If I try this logic in my code this happens:
result = list(app_tables.register_2020.search(tables.order_by(‘data’,ascending=False))[0:5])
print(result)
if query:
result = [
x for x in result
if query in x[‘Name’]
or query in x[‘id’]
return result
output:
[<LiveObject: anvil.tables.Row>,
<LiveObject: anvil.tables.Row>,
<LiveObject: anvil.tables.Row>,
<LiveObject: anvil.tables.Row>,
<LiveObject: anvil.tables.Row>]
Yes I have set data binding in the repeating panel.
Here is a clone of my app.
In the second tab “Vertetim page” if you search Besar it will return all the rows with my name. I want to return in the repeating panel only six rows not all.
Thank you so much, this code works perfectly. I just realized that even with my code works if I just put [:5] after return result [:5] it shows only 5 row. Great.