Count Data inside Repeating Group?

Hi, just want to ask i want to add an info which will count the number of rows in the Repeating Group

ex. a Top List so first row of RG will be Top 1 then next row will be Top 2 and so on

i tried to do the current cell’s index but when i set the RG to Fixed Number of 5 then add a next button the count will retain from 1 to 5 which supposed to be the next will be 6 to 10

image

its giving me a count of how many RG Info is showing
rg1

it should be like this
rg2

i use currenct cell’s index to do that but the problem is if i set the RG to Fixed Number, the next page will be the same number of 1 to 5 instead of 6 to 10

Oh, I see. I assumed you meant “count up”.

To get the ranking, you can do a :count where the sorting field is < (or >) than the current value + 1.

So if you have values …

10
15
20
35
45
47

Then search for values < current cell value (sorted on value) : count + 1

1 Like

I think he actually wants to show the relative position of the record in the entire record-set, not just the current visible records. So if there are 30 records and he is showing them 5 at a time and is on page 3, he wants the cell index to be 11-15 and not 1-5.

One way you could do this is do create a hidden repeating group that retrieves your data and then in your visible repeating group that you have set to Fixed number, reference the hidden repeating group as your data source. The use a custom state to control your pagination.

So if you data is coming from a table called “score” you create a hidden repeating group that does a search for records from score. Create a custom state on the page, or the repeating group, called currentDataPageStartIndex as a number type and in an on Page Load workflow, set it to 1.

Then you create your visible repeating group, make its content type be the same as the hidden RG and make the source be - ReapeatingGroup score’s List of scores:items from #pageName’s currentDataPageStartIndex

On your visible repeating group have a text element which has this expression for the text value - pageName’s currentDataPageStartIndex + Current cell’s index - 1

Finally have a Previous 5 button with a workflow that SUBTRACTS 5 from the currentDataPageStartIndex and a Next 5 button that ADDS 5 to the currentDataPageStartIndex

You will need to add conditions to the buttons to disable when you get to the start or end of the record-set. pageName’s currentDataPageStartIndex is 1 and pageName’s currentDataPageStartIndex + 5 > ReapeatingGroup score’s List of scores:count respectively.

here is an example https://helpexamples.bubbleapps.io/version-test/disconnectedrecordset?debug_mode=true

and the editor is you want to see how it is done.

1 Like

Yes, that is what mine does. It counts up the records that come before the current one, and adds 1. That gives you the position in the entire list.

Then you can count up the total, and do “15 out of 55” and that sort of thing.

Personally I think it is a much simpler way of doing it, but hey.

Oh, I see. You are saying that if there is a numeric value in the recordset, you can simply have the text element in the cell do a search for all the values lower than the current value and then take a count of that and add 1 to the result to get your relative index. Yes, your’s does work as well. I must have read your solution 4 times and didn’t catch on to what it was doing.

That being said, your solution does do 5 searches and counts for every data page loaded, so while yours may be simpler, mine is more efficient. =)

Also, it…doesn’t work if you are doing textual values or if there are duplicate numeric values, right?

@NigelG I kind of like your approach as it looks more cleaner and simpler.
But I’m a bit concerned about the (time) complexity /efficiency which is quadratic ( O(n^2) ) in the size of the data. That is for each element (from 1 to n) we have to search through the whole list of n items.
For smaller data size this may not be an issue but for a large one it may be. Also it will depend on how efficient bubble searches are.

Edit
@mguerrasio already mentioned the efficiency.

Yes, all depends on your use case and how you can do the counts.

So a couple of solutions :slight_smile:

I do think it should be easier than it is!

thank you so much guys, both are great & tried both of them but i used @NigelG because its much easier to do because all i need is to do a search and add a constraint :slight_smile: