Mar 05, 2024 01:05 PM
Hello everyone,
I am actually building a carousel using the Web API. I am going over the documentation and I cannot find a way to do what I want. I am trying to get the previous and next row with an id of one row in a filtered table.
For exemple, I have the following data:
ID | Name | Category
1 | D | CategoryZ
2 | B | CategoryZ
3 | C | CategoryL
If I want to get the previous element and next element of B when the table is filtered by the Category column and Name column. In this case, the previous element is C and the next one is D, How do I do that using the Web API?
The only thing I could maybe think of is a way playing with the "offset" parameter. Maybe I am missing something in the documentation.
Thank you in advance
Mar 05, 2024 09:04 PM
FWIW I think I'd use the offset as well
Mar 06, 2024 02:04 AM
Ok, but how do you do?
From what I see the offset allow you to get the element starting from a certain point.
How do you create an offset? How do we use this to say start from the X rows?
The offset from what I see is not the id of a row. It's in a form "itr-something/id".
This is ok if you do a infinite pagination but in the case of a carousel, I am a bit confuse.
I can play to get the previous one by reversing the order and the next one using the ascendant and only put the result to one element. However, I am stuck with the creation of the offset.
Mar 06, 2024 02:48 AM - edited Mar 06, 2024 02:49 AM
Yeah, once we make the first call we'll get the offset and store it, and then you'd create your own logic to store the order and use the offset as needed?
Example workflow:
1. Your carousel has 3 items, so your initial query has a pageSize of 3 and you store the offset that came with that (offset1)
2. The user hits the right arrow to see the next 3 items, so you do another query and send the stored offset (offset1)
- You get a new offset back, so you store it (offset2)
3. User hits right arrow again, so you send offset2 with your query and display the received data
- You get a new offset back, so you store it (offset3)
4. User hits left arrow, so you send offset1 with your query to display the data the user expects
(I'd probably just grab all the relevant records from a view that was sorted / filtered as needed and then use that data, really, but I assume you've got some sort of business requirement that prevents that)