Display rows in repeating panel

Hello,

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  

Thanks

Hi there,

Could you index the list search iterator (similar to a list) when it is returned?

Example:

result=app_tables.register_2020.search(tables.order_by('data',ascending=False))[0:5]
1 Like

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.

Period Name Value
December 2021 Besar 1000
November 2021 Besar 1000
October 2021 Besar 2000
September 2021 Besar 1000
August 2021 Besar 1000
July 2021 Besar 1000
June 2021 Besar 1000
May 2021 Besar 1000
April 2021 Besar 1000
March 2021 Besar 1000
May 2021 John 1000
April 2021 John 1000
March 2021 John 1000

Can you print the result of the .search() call with the slice [0:5]?

You mentioned that the panel doesn’t show anything so I’d like to know what the result of the search result is.

this is the search result:
<anvil._server.LiveObjectProxy.Iter object at 0x000000000226ade8>

What is the result of len() on that object.

I’m trying to determine if there is actually data there.

result = len(app_tables.register_2020.search(tables.order_by(‘data’,ascending=False)))
print(result)
result is 3221

Okay, so it seems like there is data in there.

I assume that using [:5] gives you the result 5 then too?

I can’t understand why the repeating panel would be empty if you are setting its items to a list of dicts (or non-empty search iterator).

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]

on if query in x[‘Name’]

If you cast the sliced result to a list, it seems to work.

rows=list(app_tables.my_table.search()[:5])

Here’s a clone:
https://anvil.works/build#clone:JLBP4UDTVBAR7S2B=33OWBTWLD4Y22RDSAF4VNRJX

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>]

but still the the repeating panel is empty.

Yes, my clone returns a subset of the total number of rows (even after sorting this works). This, I believe, is the same as what you are trying to do.

Edit: oh I see you are doing further filtering. Still, there is data there and so I suspect data binding hasn’t been set correctly

Have you set data binding in your repeating panel?
Can you share a clone?
Could you format your code with backtics?

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.

https://anvil.works/build#clone:7LPVXM5WDKB4H6JF=YWPDL6J3SQPKC4GKRMDOSECM

1 Like

and one suggestion on how to format the numbers without showing decimals formating the data binding different from “1.02f” %

Let’s stick to one question at a time.

“Besar” returns no rows because it does not match any of your conditions.

“Admir” on the other hand will indeed populate the repeating panel.

For example, return result[:5] and the search term “Admir” will work as expected.

However, you can do this filtered text search using query operators.

Something like this would work better/cleaner/faster:

result = list(app_tables.register_2020.search(  
    q.any_of(
      emer=q.ilike(f"%{query}%"),
      id=q.ilike(f"%{query}%")
    ))[:5])

Here are the docs:

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.

1 Like