| Joomla: Integrating Joomla Built-in Paging to your components |
|
|
| Sunday, 07 October 2007 | |||||||
|
Introduction In this tutorial we will explain how to implement paging using Joomla built-in features. Paging is essential in web development since large datasets are not recommended to be sent to client browsers. How it works... mySQL has a nice feature when it comes to pageing. If you add ' LIMIT 10, 20 ' at the end of your query the database engine will return recordset rows from 10 - 30 (we assume that the recordset is larger than 30). The code There are two parameters that are used to pass paging info between pages: limit and limitstart. First is used to define how many rows will be returned per page and the other one defines the page from where the paging starts. To retrieve this two params you can use the following lines
You can put this two lines on the beginning of your component since it is commonly used by all routines that handle database. Next step is to find out how many rows will be returned by the query on which you intend to implement paging.
Now we must make sure that we set $limit and $limitstart variables in case they haven't been set yet.
The first line sets the $limit to 15 if it hasn't been set yet. That means 15 items per page. User can change this number later using a drop-down box. Now we must include pageNavigation.php and create mosPageNav object.
Then execute a real query with all fields we need to display our items, and pass $limitstart and $limit to $database object.
This will write all users on current page to client browser. To draw paging we use the following code.
This last piece of code can be rearranged, so you can fit it to your component the way you like it. Summary This is very basic example of paging implementation in Joomla component, but as the complexity of your component grow the prinicpe stays the same. Joomla and mySQL functionality makes paging implementation easy. |
|||||||
| < Prev |
|---|