Help

Getting next and previous row depending on filterByFormula

365 3
cancel
Showing results for 
Search instead for 
Did you mean: 
justalk
4 - Data Explorer
4 - Data Explorer

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






3 Replies 3

FWIW I think I'd use the offset as well

justalk
4 - Data Explorer
4 - Data Explorer

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.

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)