Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination Method via API #42

Open
bhapps opened this issue Dec 26, 2018 · 4 comments
Open

Pagination Method via API #42

bhapps opened this issue Dec 26, 2018 · 4 comments
Assignees

Comments

@bhapps
Copy link

bhapps commented Dec 26, 2018

ReActiveAndroid Version:
latest

Bug or Feature Request:
Access to method of pulling data from DB as Pagination

Description:
Another great feature I would like to see is access to API method of basic Pagination fetching;
User can, via code, pull List via pagination:

  • pass Table.class
  • pass limit params
  • pass order by params
  • pass column to order by params
  • pass first id & last id to BETWEEN or;
  • pass last id to perform where("id > ?", lastId)
public List<> fetchPagination(Long firstId, Long lastId, int limit, String orderBy, db.class myModelClass) {

            List<myModelClass> result = new ArrayList<myModelClass>();
            String defaultSortBy = "DESC";
            if(sortBy !=null){
                defaultSortBy = sortBy;
            }

            List<myModelClass> myModelClassList = Select.from(myModelClass.class).where("id > ?", lastId)
                        .orderBy("id " + defaultSortBy)
                        .limit(limit)
                        .fetch();

                result = myModelClassList ;

            return result;

}

I use the above internally to do this, however would be great if was accessible via API within the library.

@lucazin
Copy link

lucazin commented Apr 10, 2019

any news about this new feature ?

How i can paginate using the code above from bendothall ? How can i call this functons and where ?
i want use loadmore function
Thanks!

@bhapps
Copy link
Author

bhapps commented Apr 13, 2019

Create a helper file with this method and use in activities or fragments when requesting load more (scrolled to bottom) and pass data to your adapter;

  • I haven't figured how to pass database.class yet, so you have to hard code the database.class manually;

  • Issue are when ids are missing/deleted from database, you wont get full row count
    i.e: 2x ids are missing and limit is set to 50 so you will only get 48 rows due to the missing ids.

  • After each call to method, you need to update the firstId value to pass again on next method call;
    i.e: Long firstId = lastId+1;

@bhapps
Copy link
Author

bhapps commented Apr 13, 2019

@ImangazalievM if I was to develop this API, were would you prefer the code to be located on pull requests

i.e: ReActiveAndroid/reactiveandroid/src/main/java/com/reactiveandroid/query/
i.e: ReActiveAndroid/reactiveandroid/src/main/java/com/reactiveandroid/api/

@ImangazalievM
Copy link
Owner

@bendothall pagination feature requires much more detailed analysis and it should be moved in the separate module of the library. I've been busy lately, but I'm planning a big refactoring for this summer and the new major release of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants