“teaPagination” Documentation by “Basilio Fajardo Gálvez” v1.0


“teaPagination”

Created: 11/01/2013
By: Basilio Fajardo Gálvez
Email: bfgnet@yahoo.es


Table of Contents

  1. Description
  2. Features
  3. Installation
  4. How To Use
  5. JavaScript
  6. Sources and Credits

A) Description - top

teaPagination is a script that allows you to paginate a sql statement or an array of data, is powerful and flexible as it has all the functionality to page any data you want.

DataTable Example

Customize Example


C) Installation - top

  1. Unzip the file on the server root
  2. Included in their projects teaPagination.php file.
    <?php require('your/path/teaPagination.php'); ?>
  3. Open in folder examples setting/setting.php and write your data connection to the database
  4. Execute countries.sql in your database.
  5. If you use the ajax page should include jquery plugin that is disposed within the header labels html document.
    <script src="your/path/teaPaginate.js" type="text/javascript"></script>

C) Features - top

  1. Easy to use, with a few lines of code get great results
  2. Url and Ajax Pagination
  3. Allows friendly url
  4. The list is customizable
  5. It is very extensible
  6. has added a jquery plugin to interact with the server in the most simple

D) How to use - top

Before initializing the object must have prepared the data, which can be an array or sql query already formed.

$data = 'Select * from countries'; /*or*/ $data = array('a','b','c','d');

Set options for pagination

$options = array();
OptionDescriptionDefault Value
maxButtons (integer)Sets the number of buttons to display5
itemsPage (integer)Number of rows to display5
beginLoop (string)Sets string to the begin of the loopNONE
endLoop (string)Sets string to the end of the loopNONE
beginTagItem (string)Sets a string at the beginning of the iterationNONE
endTagItem (string)Sets a string at the end of the iterationNONE
ajax (boolean)It does not show the button link pagefalse
nameVar (string)Parameter name containing the page numberpage
urlPage (string)Allows you to customize the output urlNONE
textNotFound (string)Text to be displayed when the data list is emptyNot found Record.
connect_db (array)This option sets the connection parameters to the database:
  1. user: name user
  2. database: name database
  3. password
array('user' => '','database' => '','password' => '')
buttons (array)Customize output buttons:
  1. btNext(boolean): Display the next button
  2. btNextTitle(string): Set button text
  3. btPrevious(boolean): Display the previous button
  4. btPreviousTitle(string): Set button text
  5. btFirst (boolean): Display first button
  6. btFirstTitle(string): Set button text
  7. btLast(boolean): Display last button
  8. btLastTitle(string): Set button text
  9. class(string): Define button styles
array('btNext' => true,'btNextTitle' => 'Next »','btPreviousTitle' => '« Previous','btPrevious' => true,'btLastTitle' => 'Last','btLast' => true,'btFirstTitle' => 'First','btFirst' => true,'class' => '')

Create an instance of the class

$pagination = new teaPagination($data, $options);

Create the list using the loop method

$pagination->loop($item_design, $callback=null, $callArgs=array());

$item_design is a string that replaces a word key by the value obtained from the data source. For example, if you have a field named 'lastName' that it replaced by its value chain adding the word {lastName}. $callback is a name function for display a more complete list, so calling an external function that will be called for each iteration of data. For example, to obtain a list of active users from the data source:

function create_list($data){if($data['user'] == 'active')return '<div>'.$data['name'].'</div>';}

And finally display the list and buttons

echo $pagination->render(); /* list */ echo $pagination->buttons(); /* buttons */

Public variables:


D) JavaScript - top

For ajax paging to use the plugin for jquery teaPaginate.js, add the following line of code between the head tags in html document:

<script src="your/path/teaPaginate.js" type="text/javascript"></script>

Now create the object for manipulation

var element = document.getElementById('example');
var paginateExample = new teaPaginate(element,{    
    url : server.php,
    buttonsContainer : 'nameElement',
    OnLoad : handlePagerSuccess,
    OnBefore: handlePagerBefore,
    textLoading: 'Loading...',
    data:{page:1,init:true}
}).init();

Options:

Methods:


E) Sources and Credits - top

JQuery has been used as external library and FirePHP.

Basilio Fajardo Gálvez