How to implement pagination in Mobile application?

Hi Folks,
Greetings!


I would like to implement pagination in mobile app.

In my mobile application there is one feature that the users posted photos and posted photos are live for application users so all users can like and comments on that posted photo. So there might be multiple likes and comments for each photo or record.

And there might be thousands of posts in Post-Photo-Entity (created in Server to save photos) and multiple likes and comments in separate entities. So here I am able to fetch limited records from photo-Entity (By passing Max record length to Entity), But the issue is how to fetch Likes and comments for fetched photo records, instead of fetching all likes and all comments from their entities.

Also don't want to use For loop and compare each and every Photo Id with their likes and comments in likes and comments entities respectively.

Kindly let me know what would be the better way to implement pagination for this scenario in mobile application.


Thanks



Hi Meer Imtiyaz,

You might want to see this post about pagination in mobile (consider instead infinite scroll pattern): https://www.outsystems.com/forums/discussion/21686/list-pagination-for-mobile/

In your datamodel consider to separate attributes of type binary, from other content to be listed (have in mind datamodel best practices): https://success.outsystems.com/Documentation/Best_Practices/OutSystems_Platform_Best_Practices

Finally, in your solution, you might want to have a "see more details" action to further expand more sub-lists.

These are only a few tips, to help in your implementation decision.

Cheers!

Marco Arede wrote:

Hi Meer Imtiyaz,

You might want to see this post about pagination in mobile (consider instead infinite scroll pattern): https://www.outsystems.com/forums/discussion/21686/list-pagination-for-mobile/

In your datamodel consider to separate attributes of type binary, from other content to be listed (have in mind datamodel best practices): https://success.outsystems.com/Documentation/Best_Practices/OutSystems_Platform_Best_Practices

Finally, in your solution, you might want to have a "see more details" action to further expand more sub-lists.

These are only a few tips, to help in your implementation decision.

Cheers!

Hi Marco Arede,
Thanks for your response!

I have implemented infinite scroll pattern already and fetching records in chunks but the issues is how to fetch likes and comments of that chunk records without comparing each and every fetched chunk records photo Id with Likes and Comments photo id in their entities.

Other hand,
I only want to fetch all Likes and comments with are related to fetched photos chunk records only but not for all posted record's Likes and Comments.


Thanks



Hi Meer Imtiyaz,

And could you share your eSpace, or a datamodel diagram, so that we can help you further?

Thanks!

Marco Arede wrote:

Hi Meer Imtiyaz,

And could you share your eSpace, or a datamodel diagram, so that we can help you further?

Thanks!

Please see below the screenshot of data model diagram.

Have you tried aggregating the photos with the likes, grouping by the photo parameters you're gonna need and Counting the likes?

Mariano Picco wrote:

Have you tried aggregating the photos with the likes, grouping by the photo parameters you're gonna need and Counting the likes?

Hi Mariano Picco,
Thanks for your reply!

I was tried by aggregate also, but did not able to use photo entity in Like or Comments entity to get the related Likes or Comments.

Can you please let me know the flow or one example how to do by using aggregate?

Thanks


Hi Meer Imtiyaz,

For the likes it is fairly simple to achieve, in the Aggregate that fetches the Photos (and is already used for the infinite scrolling), and JOIN with the Likes entity. Then you can GROUP BY the relevant attributes of Photos and perform a COUNT on the Id of Likes to get the number of likes for each photo.

Note that this will change the output of the Aggregate (instead of .List.Current.Photos.Title you would instead have .List.Current.Title), and Service Studio will not update the places where you were using the output, so you will need fix the errors that show up manually.

This approach will not work for Comments however, as I imagine you want more than just show how many are there. You will need to fetch them separately. My suggestion is you create a Block to show all the comments of a Photo, and pass that Photo's Id as input parameter. Inside the Block you can add a second Aggregate that fetches Comments based on the Photo's Id input parameter. This would likely trigger a performance warning however, as for each photo you're querying the database for comments.

Hope this helps.

Jorge Martins wrote:

Hi Meer Imtiyaz,

For the likes it is fairly simple to achieve, in the Aggregate that fetches the Photos (and is already used for the infinite scrolling), and JOIN with the Likes entity. Then you can GROUP BY the relevant attributes of Photos and perform a COUNT on the Id of Likes to get the number of likes for each photo.

Note that this will change the output of the Aggregate (instead of .List.Current.Photos.Title you would instead have .List.Current.Title), and Service Studio will not update the places where you were using the output, so you will need fix the errors that show up manually.

This approach will not work for Comments however, as I imagine you want more than just show how many are there. You will need to fetch them separately. My suggestion is you create a Block to show all the comments of a Photo, and pass that Photo's Id as input parameter. Inside the Block you can add a second Aggregate that fetches Comments based on the Photo's Id input parameter. This would likely trigger a performance warning however, as for each photo you're querying the database for comments.

Hope this helps.

Hi Jorge Martins,
Thanks for your reply!

Actually my functionality for Mobile app, so my database is in Server module and by using Sever wrapper fetching records. But currently I am fetching Max records(with passing Limit count) for Photos, and for Likes and Comments fetching all Likes and comments.

In infinite scrolling I am passing input values i.e. Limit, Last_PhotoId in Server wrapper action to fetch photos in chunk. So What I need is whatever the likes and comments are related to that fetched photos records chunk that should be come in output parameter from Server action to Mobile device. 

Kindly let me know if you expect more details.


Thanks






Solution

Folks,

I have got the solution for my query.

Jorge Martins, I have taken support from your post i.e. "For the likes it is fairly simple to achieve, in the Aggregate that fetches the Photos (and is already used for the infinite scrolling), and JOIN with the Likes entity. Then you can GROUP BY the relevant attributes of Photos and perform a COUNT on the Id of Likes to get the number of likes for each photo." But need some changes that are below.

In Server wrapper I have taken one more Photo entity with all filters applied and added Likes entity in Photo entity as source with INNER JOINT (Only with) and fetched all Likes which are related to fetched photos chunk records.

And same did for comments.

Thanks to all guys for your valuable and good support! (Y)


Solution