Page 1 of 3

Pagination not quite working as expected

Posted: Fri Apr 04, 2014 11:01 pm
by Mike Maughan

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


Pagination not quite working as expected

Posted: Sat Apr 05, 2014 1:00 am
by Igor

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


Pagination not quite working as expected

Posted: Sat Apr 05, 2014 3:36 pm
by Mike Maughan

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!


Pagination not quite working as expected

Posted: Sat Apr 05, 2014 3:45 pm
by Igor

Could you post app public link?


Pagination not quite working as expected

Posted: Sat Apr 05, 2014 9:43 pm
by Mike Maughan

Pagination not quite working as expected

Posted: Sun Apr 06, 2014 8:23 am
by Igor
  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".

Pagination not quite working as expected

Posted: Mon Apr 07, 2014 12:53 pm
by Mike Maughan

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


Pagination not quite working as expected

Posted: Mon Apr 07, 2014 5:33 pm
by Kateryna Grynko

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.


Pagination not quite working as expected

Posted: Mon Apr 07, 2014 9:54 pm
by Mike Maughan

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


Pagination not quite working as expected

Posted: Tue May 06, 2014 4:42 pm
by Alex GG

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!!