Mike Maughan
Posts: 0
Joined: Wed Feb 19, 2014 10:55 pm

Pagination not quite working as expected

Following the pagination tutorial, I add a query to the database with a where clause. When I add a count value, the return is undefined except for the count, which has a value. When I leave out the count value the return is the page of results.

Not sure what I might be doing wrong. Any insight would be appreciated. What might I provide?

Thanks!

Mike

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Pagination not quite working as expected

Hello,

I've checked Building a mobile app with data pagination tutorial
There is small issue with escape symbols(code< and >/code) in the code:

  1. In the section #3 http://docs.appery.io/tutorials/build...

    replace code from tutorial :
    pre
    code
    var skip = parseInt(localStorage&#46;getItem('skip'));
    var limit = parseInt(localStorage&#46;getItem('limit'));
    var total = parseInt(localStorage&#46;getItem('total'));

    if (limit + skip > 0){
    localStorage&#46;setItem('skip', skip-limit);
    get_states&#46;execute({});

    if (skip - limit == 0){
    Appery('prevButton')&#46;hide();
    }
    if (skip - limit < total - limit ) {
    Appery('nextButton')&#46;show();
    }
    }
    /code
    /pre

    with the following one :
    pre
    code
    var skip = parseInt(localStorage&#46;getItem('skip'));
    var limit = parseInt(localStorage&#46;getItem('limit'));
    var total = parseInt(localStorage&#46;getItem('total'));

    if (limit + skip > 0){
    localStorage&#46;setItem('skip', skip-limit);
    get_states&#46;execute({});

    if (skip - limit == 0){
    Appery('prevButton')&#46;hide();
    }
    if (skip - limit < total - limit ) {
    Appery('nextButton')&#46;show();
    }
    }
    /code
    /pre

  2. Code from section #4
    pre
    code
    var skip = parseInt(localStorage&#46;getItem('skip'));
    var limit = parseInt(localStorage&#46;getItem('limit'));
    var total = parseInt(localStorage&#46;getItem('total'));

    if (limit + skip < total){
    localStorage&#46;setItem('skip', limit+skip);
    get_states&#46;execute({});

    if (limit + skip == limit) {
    Appery('prevButton')&#46;show();
    }

    if (limit + skip == total - limit) {
    Appery('nextButton')&#46;hide();
    }
    }
    /code
    /pre

    with the following:

    precode
    var skip = parseInt(localStorage&#46;getItem('skip'));
    var limit = parseInt(localStorage&#46;getItem('limit'));
    var total = parseInt(localStorage&#46;getItem('total'));

    if (limit + skip < total){
    localStorage&#46;setItem('skip', limit+skip);
    get_states&#46;execute({});

    if (limit + skip == limit) {
    Appery('prevButton')&#46;show();
    }

    if (limit + skip == total - limit) {
    Appery('nextButton')&#46;hide();
    }
    }

    /code/pre

Mike Maughan
Posts: 0
Joined: Wed Feb 19, 2014 10:55 pm

Pagination not quite working as expected

Thanks for your reply. Here's a follow up question. On page show I have the read db service return a count, which value is passed to the total local storage variable. then I invoke the list states service. the issue is that I get an undefined value returned for the count. Yet testing the read db service shows a number returned successfully.

Any suggestions?

Thanks!

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Pagination not quite working as expected

Could you post app public link?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Pagination not quite working as expected

  1. On "startScreen" load event you don't define "total" localstorage variable. You need to add this code:
    pre
    localStorage&#46;setItem('total', 50);
    /pre
    http://docs.appery.io/tutorials/build...
    1. Delete "total" localStorage variable in the mapping "Pagination_DB_States_read_service".
      http://docs.appery.io/documentation/r...
    2. On the next and prev buttons event click you are executing data source name
      codeget_states&#46;execute({});/code but datasource name is "show_states". You should change data source name to "get_states".
Mike Maughan
Posts: 0
Joined: Wed Feb 19, 2014 10:55 pm

Pagination not quite working as expected

Hi Igor,

Thank you for your reply. I somehow overlooked the "get_states.execute){()};" misspelling.

However, there is a reason that I am trying to assign the "total" localStorage variable value from a query result count rather than assign a static value on page load. I'm working on another pagination app whose number of pages is determined by the 'where' database query they perform, and so the 'total' value needs to be dynamic rather than a static value assigned on page load.

You can see that there is javascript on the where request variable just for testing purposes, which says to return any state that starts with "New", which there are just four total. With 'limit' set to 2 and 'skip' set to 0, I should have two pages of results.

  1. When I request the count as a return variable/value, the query only returns the count. This is why I have a read db service split from the list db service, as a work around. Can you request a count among a query response and have it not be the only thing that is returned?

  2. While I have split out the "total" localStorage variable value assignation with the read_db service, it shows a value of "undefined". Yet when I test the service, it returns a value with no errors. Am I missing something to make the returned value, that tests okay, to map to a local storage variable and to a label text?

    Thanks!

    Mike

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Pagination not quite working as expected

Hi Mike,

1) In service read_db request parameters set parameter 'count' = 1.

2) You have an incorrect response parameters structure in Pagination_DB_States_read_service settings. Click Test and use the result to Automatically Create Service Response (don't forget to change mapping after this).

3) [quote:]Can you request a count among a query response and have it not be the only thing that is returned[/quote]No, you can receive all the values and on service Success event see how many values are received. Please note that you will receive all the records that will significantly increase data traffic. It's up to you to decide whether you really need this.

Mike Maughan
Posts: 0
Joined: Wed Feb 19, 2014 10:55 pm

Pagination not quite working as expected

Thank you, everyone for your assistance! I think you can consider this closed.

Alex GG
Posts: 0
Joined: Thu Nov 14, 2013 11:11 pm

Pagination not quite working as expected

Hi!
Im implementing paginations in my app because I have a lot of records with text and images...

I ́ve managed to have the tuturial working...
But what I want to do is just to have the NEXT button (load more)...so every time the user clicks this button more elements are added to the list...
Righ now, the elementes are been updated by the new ones.

For example, on page load I want to show just 10 elements, if user clicks "load more" the list should have 20 elements...

What should I do to perform this task?

Thanks!!

Return to “Issues”