Hi community,
We have a dropdown where people can choose how many products need to be showed (by default it is 4).
This is working correctly when you are on page 1 but is not working correctly when you change the amount of products when you are on page 2 and so on.
Does anyone have any ideas on why this is not working correctly? I'll try to make as many screenshots as possible to show the logics I have right now (since I am not able to share the .oml). If you need anything else, please let me know.
Ok, yes,
with an aggregate in a screen, you give it a startindex, and the platform makes sure that underwater the correct set of records gets returned. So if you have a server action, you'll have to do that yourself.
See attached oml, i don't really have time to test it, but you basically use startindex + maxrecords as maxrecords on your server side aggregate, and you have a loop to fill server output, using startindex and maxrecords to get the correct set into your server output.
This has the advantage of only sending the set for the current page back to the screen instead of everything.
What you are doing now in your screenprints, is you send everything back, and then loop in your onAfterFetch.
Dorine
Have a look at this asset that explains to you how to.do.pagination to data coming from data actions or rest APIs.
https://www.outsystems.com/forge/component-overview/7700/list-pagination-reactive
Remember, this asset/component just explains.
Kind Regards,
Marcio
Hi Marcio,
Thanks for your reply. I did exactly as the component describes. And that part is working as expected. the problem starts when you are on page 2 and then adjust the number of products to be displayed. The problem is that the StartIndex is staying on 4 where it should be 0 again.
I think I found a solution. Since the product list is in a webblock and the dropdown is outside of it I can use the On Parameters Changed event. When the MaxRecords value changes I do reset the StartIndex to 0.
That way it works?
That is indeed what is intended to do when you change the inputs you want use to retrieve your data.
Regards,
Márcio
Hi Bart,
So for starters : am I understanding correctly, your data action does not take pagination into account, but always retrieves all records ?
In you second screenshot, you are saying in the remark that you are back on page 1, but you don´ t seem to have reset the startindex.
Can you show the action flow when user selects other maxrecords value in the dropdown ?
Hi Dorine,
No, based on a lot of input parameters the products are retrieved (see screenshot below as a reference).
Basicly, I have a static entity with the amounts (4 and 8) in it and it is binded to the dropdown. The value of it is placed in the MaxRecords variable. In my webblock I have a input parameter called MaxRecords and I did attach the dropdown variable to the input parameter. So in that way the amount of products is binded to the webblock.
As you are mentioning that the StartIndex is not being reset I think you found the problem since I think it should be resetted to 0 again. See my reply to Márcio as how I tried to solve it. It seems to work..
I'm not really getting it, in your response to Marcio, I see you are refreshing the data action (as I think in most cases, you should be doing), so then why not use the StartIndex and maxRecords immediately in that dataAction.
If you do, then it doesn't make sense to me that you are using them to loop and append to the local list ??
I was not able to do it directly in the Data Action. So I entered the OutSystems forum to see if I could find a solution. I found two from the posts below:
Also the refresh part was already in the On Parameters Changed Event. The only thing I did add was the MaxRecords <> -1 so the StartIndex will get reset to 0 since this was not happening as you mentioned earlier.
Maybe I am overthinking too much? Do you have a solution to use MaxRecords and StartIndex directly in a Data Action that can be used with pagination?
Thanks,
Bart
Well,
that depends on how complex that data action is.
Is the list of records returned exactly the list of for example an aggregate that you execute inside it ? In that case you can use them on the aggregate. Can you give some more detail on the data action ?
Also, if you for some reason don't want or can't use maxrecords and startindex in your data action, then there is no point in doing the refresh in the OnParametersChanged, your data action will retrieve the full list, and you only have to redo the listClear + listAppends taking into account the changed maxrecords/startindex (so instead of that refresh in your screenprint)
This is how the flow of the Data Action is looking. The first aggregate is used to get some data that is needed to fill one of the input parameters in the server action. At last I assign the list of the server action to my output parameter.
What we need to see is where the data comes from, so inside that server action.
Is there an aggregate in there on which you can apply your startindex and maxcount ?
I am doing a lot of things in the server action but eventually everything is coming together in the aggregate (see screenshot below). Normally when you are in a screen and run a aggregate you have the option to put a StartIndex and a MaxRecords. That is the reason I do not see a option to do it in this way. But maybe I am wrong.
Thanks for your reply. I will test it out since I think this is a more solid solution!
I would suggest one small change to the approach posted by Dorine: instead of the "For Each Loop". use a list filter on the aggregate's row number to be greater than the Start Index and less than Start Index + Max records as the List filter is much faster than the For Each loop. However, I would have hoped there were a better way to do this that would allow us to use the start index and max records directly in the aggregate in the action.