[SalesForce] Pagination with Lightning Components

I am trying to implement a simple paginator that uses a wrapper object to move between pages, but I am not sure how to get the wrapper class to work in the component controller. Specifically my questions are:

  1. How to invoke the inner-class method void next() from the component controller, given it is not a getter?
  2. Can I call non-Aura methods from the component controller?
  3. Can I call non-static methods from the component controller?

The documentation clearly answers questions 2 & 3 with a "no," but I wanted to be sure just in case there were exceptions to the rule.

The following code is not compiling with this error:

AuraEnabled methods must be named with a prefix 'get'

public class PageController
{
    @AuraEnabled
    public static QueryCursor getAccounts()
    {
        return new QueryCursor();
    }

    public class QueryCursor
    {
        private Integer m_pageNumber;

        public QueryCursor()
        { 
            m_pageNumber = 1; 
        }

        @AuraEnabled
        public Account[] accounts
        { 
            get { return queryAccounts(m_pageNumber); } 
            private set; 
        }

        @AuraEnabled
        public void next() 
        { 
            m_pageNumber++; 
        }

        private Account[] queryAccounts(pageNumber)
        {
            // return Accounts with an offset
        }
    }
}

I understand why I'm getting the error, but I don't want to change the signature from void next() to Account[] getNext(). What's the best way to go about this?

Best Answer

Pagination isn't accomplished server-side in Lightning; but instead done by client-side code. See my gist for an example that loads up to 50,000 rows. If you need more than that, you simply need to load the data from the server in pieces, as demonstrated here; basically, just query X number of records, and if there's still more data to get, use the ID as a condition for the next query to get the next "page" of data. Lightning is fast enough that you should be sorting and paging client-side without resorting going back to the server all the time.