Pagination Library
revIgniter's Pagination library is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.
If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:
« First < 1 2 3 4 5 > Last »
Example
Here is a simple example showing how to create pagination in one of your controller handlers:
rigLoaderLoadLibrary "Pagination"
put "http://example.com/index.lc/test/page/" into tConfig["baseUrl"]
put 200 into tConfig["totalRows"]
put 20 into tConfig["perPage"]
rigInitializePagination tConfig
put rigCreatePaginationLinks() into gData["pagination"]
Notes:
The tConfig array contains your configuration variables. It is passed to the rigInitializePagination handler as shown above. Although there are some twenty items you can configure, at minimum you need the three shown. Here is a description of what those items represent:
- baseUrl This is the full URL to the controller/handler containing your pagination. In the example above, it is pointing to a controller called "test" and a handler called "page". Keep in mind that you can re-route your URI if you need a different structure.
- totalRows This number represents the total rows in the result set you are creating pagination for. Typically this number will be the total rows that your database query returned.
- perPage The number of items you intend to show per page. In the above example, you would be showing 20 items per page.
The rigCreatePaginationLinks() function returns an empty string when there is no pagination to show.
Setting preferences in a config file
If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called pagination.lc, add an array in that file, call the rigRunInitialPaginationConfig handler at the bottom of your file with the array as parameter. Then save the file in: config/pagination.lc and it will be used automatically. You will NOT need to use the rigInitializePagination handler if you save your preferences in a config file.
Example:
local sConfig
put "http://example.com/index.lc/test/page/" into sConfig["baseUrl"]
put 200 into sConfig["totalRows"]
put 20 into sConfig["perPage"]
put "« First" into sConfig["firstLink"]
put "Last »" into sConfig["lastLink"]
put "<div class=" & quote & "fullTag" & quote & ">" into sConfig["fullTagOpen"]
put "</div>" into sConfig["fullTagClose"]
# START PAGINATION CONFIGURATION
# THIS LINE IS MANDATORY
rigRunInitialPaginationConfig sConfig
Customizing the Pagination
The following is a list of all the preferences you can pass to the initialization handler to tailor the display.
put 3 into tConfig["uriSegment"]
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.
put 2 into tConfig["numLinks"]
The number of "digit" links you would like before and after the selected page number. For example, the number 2 will place two digits on either side, as in the example links at the very top of this page.
put TRUE into tConfig["pageQueryString"]
By default, the pagination library assumes you are using URI Segments, and constructs your links something like
http://example.com/index.lc/test/page/20
If you have gConfig["enableQueryStrings"] set to TRUE your links will automatically be re-written using Query Strings. This option can also be explictly set. Using tConfig["pageQueryString"] set to TRUE, the pagination link will become.
http://example.com/index.lc?c=test&m=page&perPage=20
Note that "perPage" is the default query string passed, however can be configured using put "your_string" into tConfig["queryStringSegment"]
Adding Enclosing Markup
If you would like to surround the entire pagination with some markup you can do it with these two prefs:
put "<p>" into tConfig["fullTagOpen"]
The opening tag placed on the left side of the entire result.
put "</p>" into tConfig["fullTagClose"]
The closing tag placed on the right side of the entire result.
Customizing the First Link
put "First" into tConfig["firstLink"]
The text you would like shown in the "first" link on the left.
put "<div>" into tConfig["firstTagOpen"]
The opening tag for the "first" link.
put "</div>" into tConfig["firstTagClose"]
The closing tag for the "first" link.
Customizing the Last Link
put "Last" into tConfig["lastLink"]
The text you would like to be shown in the "last" link on the right.
put "<div>" into tConfig["lastTagOpen"]
The opening tag for the "last" link.
put "</div>" into tConfig["lastTagClose"]
The closing tag for the "last" link.
Customizing the "Next" Link
put ">" into tConfig["nextLink"]
The text you would like to be shown in the "next" page link.
put "<div>" into tConfig["nextTagOpen"]
The opening tag for the "next" link.
put "</div>" into tConfig["nextTagClose"]
The closing tag for the "next" link.
Customizing the "Previous" Link
put "<" into tConfig["prevLink"]
The text you would like to be shown in the "previous" page link.
put "<div>" into tConfig["prevTagOpen"]
The opening tag for the "previous" link.
put "</div>" into tConfig["prevTagClose"]
The closing tag for the "previous" link.
Customizing the "Current Page" Link
put "<b>" into tConfig["curTagOpen"]
The opening tag for the "current" link.
put "</b>" into tConfig["curTagClose"]
The closing tag for the "current" link.
Customizing the "Digit" Link
put "<div>" into tConfig["numTagOpen"]
The opening tag for the "digit" link.
put "</div>" into tConfig["numTagClose"]
The closing tag for the "digit" link.