SFDC Monkey: Display Record With Pager Buttons In Lightning Component

A Pattern for Implementing Pagination in Lightning Components

Piyush Soni gives us a pattern for implementing pagination in Lightning Components.

Pagination is a pattern that provides data in “pages” of a set number of rows or records, with navigation controls to navigate the user through the pages of data.

Typically the navigation patterns come in the form of buttons or links that use terminology such as “FIRST,” “LAST,” “PREVIOUS” and “NEXT.”

This solution is solid but it does have a couple of potential limitations as it uses calls to an Apex controller method, and that method uses a SOQL clause called “OFFSET” to skip over the specified number of records returned by the query.

Calling the Apex controller every time you need data will subject you to potential performance bottlenecks as you are leaving the Lightning Component Framework to traverse the network and retrieve additional data from the server. The round trip itself has a cost, and the amount of data that gets returned from the server could have a very high cost from a network perspective, especially in low bandwidth situations.

The “OFFSET” clause has a limitation of 2,000 records that it can skip, after that you’ll throw an exception. This requires some defensive coding, such as adding a “LIMIT” clause to the SOQL query to ensure that you don’t get back more than 2,000 records.

Piyush provides all of the code for his solution, so if you are exploring pagination options in Lightning, this is a good resource to review to generate ideas.