Pagination
From Aikiframework wiki
|
Pagination is used to break the number of results returned from SQL query into multiple pages.
In Aiki, there is a simple way to do so, and there are many options to control how the pagination look and work.
This is how you add pagination to a widget.
Simple
If you have a widget with select statement that return results without limits. (aka: no "limit" command in the query) like select * from blog_posts, you can easily create pagination by entering the number of desired results per page in the "Records per page" field in the sql section of the widget editor.
Writing the number of desired records will limit the results and add pagination links in the bottom of the widget. Those links have CSS classes to style the pieces that display as standard pagination controls.
A simple pagination control consists of the following:
- linked page numbers
- next and previous buttons
- first page and last page buttons
Simple pagination links look like:
www.yoursite.com/some/path?page=1
The ?page=1 part of the link can be changed as well, please continue reading to see how.
Custom
The default pagination of aiki displays all the pages numbers without grouping them in google style links.
To make google style grouping of pages you have to use the (Pagination Link Example) field in sql section of the widget editor.
By adding:
config[group_by:10]
to the link example you get exact google like behaviour of pages grouping. where 10 is the number of page links to be grouped.
However, when you write anything in pagination link example field the default linking system of pagination will need to be redefined, as mentioned earlier the ?page=NUMBER part of the link is the default linking system. So first thing we need to do is to add that back, so instead of just having config[group_by:10] in the (pagination link example) it should be:
?page=[page] config[group_by:10]
(pagination link example) field also can be used to change the word (page) in page links, you can replace it with anything like:
?anyword=[page]
but the [page] part should remain the same because it get replaced in run time with page numbers
Custom
You can use (pagination( syntax to put your custom pagination.
(pagination(
(previous( <a href="[previous]"> < < </a> )previous)
<span> [currentpage] / [numpages] </span>
(next( <a href="[next]"> > > </a> )next)
)pagination)
(next and (previous content will be visible only if there are pages to them. [next] and [previous] are replaced with links to next and previous pages.
Examples
- Using [no_pagination] anywhere in the widget will entirely remove the default pages links and buttons from the widget while keeping the pagination functionality available.
- Adding [pagination] anywhere in the page will make the pages links and buttons displayed in the place where this markup is added, for example if you want it at the top of the widget instead of the bottom. please note that using this without [no_pagination] will make two copies of the page links, so if you just want the pagination links to be displayed in specific place you have to first add [no_pagination] anywhere, and then add [pagination] in the place where you want it to get displayed
- [next] and [previous] if you don't want to use the default links you can build your own next and previous links by using this markup inside custom anchor like in:
<a href="[next]">Next button</a> <a href="[previous]">Previous button</a>

