:item from# :item until#

I have been working on my search functionality and pagination within the results set and made good progress, but hit a road block that I cannot get my head around.

To simplify testing I used small record sets and set paging size to small numbers. In theory if the setup is correct it wont matter the page size it should just work.

I make an initial query to determine the record count of the results set and then set a bunch of states in the Pagination control I have built. These include RecordCount, ItemsPerPage, Pages Available, Current Page, ItemFrom and ItemTo.

After these are set, I use them to display in a repeating group the query but add the :item from and :item until operators.

Having read the documentation and done a few checks to determine which order the method chaining does work, I worked out that I need to perform the :item until first and then the :item from.

With a ItemsPerPage of 1 and ResultsCount of 5 it correctly sets up Pages available to 5 and Current Page to 1, the Page Next simply increments the item until and item from and re-displays in the group.

The problem I have is the number of records displayed on each page are as follows;
Page 1: 1
Page 2: 2
Page 3: 3
Page 4: 2
Page 5: 1

So, the question is, am I using the :item until and :item from correctly in the right order in the same statement? Iā€™ve been on this for hours today and it is really frustrating! I am sure I have been staring at this so long, and tried so many different things that I cannot see the wood for the trees now. :tired_face:

Hey Dave I may not be understanding this correctly, but are you trying to display search results in a repeating group, and then display the next set of results within the repeating group when a different ā€˜page numberā€™ is clicked? Instead of using ā€˜nextā€™ and ā€˜previousā€™ buttons?

I just tried working on this for a while and I think I got something working (I hope!).

Preview:

Editor:

I created two data types ā€œEntryā€ (containing one field: ā€œNameā€, type: text, list: no) and ā€œPage Numberā€ (containing one field: ā€œNumberā€, type: number, list: no). The main repeating group does a search for Entries, and there is a repeating group beneath it which does a search for Page Numbers and displays them 3 at a time.

On page load, I used custom states to count total the number of results in the Entry Repeating Group, and divided that by the number of rows in that repeating group which equals the Repeating Groupā€™s ā€œNumber of Pagesā€.

The Page Number repeating group will only display numbers less than or equal to the Entry Repeating Groupā€™s Number of Pages:

On page load, I set the Entry Repeating Groupā€™s Current Page to 1. Then when a next arrow, back arrow, or ā€˜numberā€™ within the Page Number repeating group is clicked, it will ā€˜go to pageā€™ in both repeating groups (Entry and Page Number) and continue to set the state of the Current Page number custom state. Not sure if this is what youā€™re looking to do, but just incase it may help :slight_smile:

3 Likes

Thanks for that Faye, but that is using fixed list. and the Goto page functionality.

I am using an Extending Vertical List, hence the reason to try and get the :from and :until operators in the search query working correctly.

I want to fully understand the use of these operators and that is where I am banging my head and canā€™t get it to do what I want. I am beginning to think that they do not support method chaining and are simply overriding each other depending on the order they are put into the queryā€¦but Iā€™m not 100% as to what is exactly going on.

More play to doā€¦at least you have a nice paging example now in the ForumApp for others :slight_smile:

Ohh! I see :slight_smile: That sounds like a very interesting problem to solve! Will follow along, and hope you find a solution!

Bubble tends to work left to right.

So if you have ā€œFrom itemā€ as 3 ā€¦ and ā€œTo Itemā€ as 5 ā€¦ it thinks you mean 5 on from 3.

The solution is therefore to subtract your ā€œFrom Itemā€ number from your ā€œTo Itemā€ and add 1 and use that in your search as ā€œ:ToItemā€.

1 Like

Thanks @NigelG, I have redesigned the page for now, but will try again later on another page which is planned.

Ok, I have made a demo page using a simple list, and it definitely does not do as I would expect from the definitions of the operators.

See the page here: https://dave-auld-demo-stuff.bubbleapps.io/version-test/fromuntildemo?debug_mode=true

It appears that the order of the From Until or Until From does not matter, and Until is actually the number of items to return after the from! So, if From is 5 and Until is 10, it does not return 5,6,7,8,9 it returns 5,6,7,8,9,10,11,12,13,14

Iā€™m not convinced it is working correctly for both operators being present in the statement, and which way round they are.

@NigelG does that make sense, or am I miles out on the expectations based on the definitions and potential method chaining.

1 Like

Yeah, you are right, ā€œuntil xā€ is x on from then item in ā€œfromā€.

Or rather until #10 in the list that has been adjusted by the from.

So I guess the question is ā€¦ is that working as intended (in which case we can ask for some wording updates) or should it work as it looks like it is described. Only @emmanuel can tell us :slight_smile:

It sounds going to be from the from. It reads as this

(List: from n): to m

Returns a sub list from the original list, from the first item to the Nth one.

So I think the wording around ā€œoriginal listā€ is unclear ?

1,2,3,4,5,6,7,8,9 = the original list. So ā€œUntil 5ā€ will give you ā€¦ 5.

However if you do a ā€œFrom 2ā€ ā€¦ the ā€œUntilā€ isnā€™t operating on the original list ā€¦ is operating on a new list ā€¦

2,3,4,5,6,7,8,9 ā€¦ ā€œUntil 5ā€ is now 6.

1 Like

And that is where Iā€™m coming from, the method chaining should be acting on the result of the previous operator, so by switching the order of the From and Until should be making a difference to the output, however it doesnā€™t.

I tried to find to some example on some of the other databases operators e.g. Mongo or whatever, but havenā€™t found time.

Whilst I agree it isnā€™t all that clear how it works ā€¦

ā€œMethod Chainingā€ is all a bit code-y. Most people who use bubble are not coders, so I would suggest it should work in the way they would expect it to work, rather than how someone technical expects it to work.

It is fairly confusing as it is.

@DaveA

I share your pain as the theory behind item until would be that i want to label it as item until the specific number; meaning I want items from 31 until items 60, we as humans would natural assume the bubble ā€œitem untilā€ should be 60 but in fact it needs to always be the number of results you want to have.

So in my app, which is set the same way as yours with custom states for the math, I have set the items until custom state to always be equal to the number of results I want displayed on pageā€¦now it works exactly as intended.

Page 1 shows items 1-30
Page 2 shows items 31-60
Page 3 shows items 61-90

because my items until is always 30 bubble does the math by saying

items from + items until = last item in list to be displayed

originally I had same set up as you and was confusedā€¦wrote on paper what was happening, saw the multiplication of my values for item until and couldnā€™t figure it outā€¦read this post, specifically from Nigel and got it.

Thanks! This solution worked to me!