TKPagedView Class Reference
[Components]

Data paginator for TK. More...

Inheritance diagram for TKPagedView:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __construct ($name, $callback, $useAjax=false, $saveState=false)
 Creates new Paged View object.
 handleAjax ()
 Handles Ajax updates.

Protected Member Functions

 build ()
 Generates the view.


Detailed Description

Data paginator for TK.

This class implements a data paginator. Data is fed to this object via a callback. All of the navigation between pages is handled by this object. It provides a few other features, such as Ajax transitions, scroll view the internal table and animations.

The basic way to use the paginator, without Ajax, is the following:

 // Create the paginator
 $pv = new TKPagedView('test', 'populateView');

 // Initialize the paginator (set the headers and the title)
 $pv->headers = array('Column One', 'Column Two');
 $pv->title = 'Test Paged View';
 // Could optionally change the table class as well
 //$pv->tableObjectClass = 'TKIPlusTable';

 // Build the component (fills in data, etc.)
 $pv->build();

 // Add to the page and print
 $prm->add($pv);

 $prm->renderPrint();

 // This is the callback, it takes three parameters:
 //  $name - name of the TKPagedView object (in this case, it will be 'test')
 //  $offset - start data at this offset
 //  $perPage - and produce up to this many results
 // The callback returns an array with the first element being the 2D array of data
 // to ppopulate the table with, and the second being the total number of results in
 // the data set
 function populateView($name, $offset, $perPage) {
     $data = array();

     for($i = $offset + 1; $i < $perPage + $offset + 1; $i++)
          $data[] = array($i, "This is some data");

     return array($data, 100);
 }

If you want to use Ajax, you just set the third parameter to the constructor to true and then call handleAjax() on the object before calling build(). It will take care of the rest of the details:

 $pv = new TKPagedView('test', 'populateView', true);

 // Initialize the paginator (set the headers and the title)
 $pv->headers = array('Column One', 'Column Two');
 $pv->title = 'Test Paged View';

 // Could optionally change the table class as well
 //$pv->tableObjectClass = 'TKIPlusTable';

 // we may also want the Ajax to animate
 $pv->animate = true;

 // Handle the Ajax
 $pv->handleAjax();

 // Build the component (fills in data, etc.)
 $pv->build();

 ... (same as before)

Constructor & Destructor Documentation

TKPagedView::__construct ( name,
callback,
useAjax = false,
saveState = false 
)

Creates new Paged View object.

You must create the paged view object before calling handleAjax() if you are using Ajax page transitions.

Parameters:
$name [string]: name of this paged view (used to distinguish different paged views on the same page)
$callback [callback]: function to call to populate the table
$useAjax [boolean]: if true, use Ajax for paging, rather than a page refresh


Member Function Documentation

TKPagedView::build (  )  [protected]

Generates the view.

This method is to be called before the object is to be rendered. Any configuration options set after build() are likely to be ignored. This method calls the callback specified in the costructor. This method is not called automatically when rendering to make it so that the population of data can be done when the user requires it, rather than at a possibly late point in script execution (rendering).

Returns:
[boolean]: success or failure

TKPagedView::handleAjax (  ) 

Handles Ajax updates.

Call this method after initializing the view object. If the script was invoked to get an Ajax response, this method will take care of building and rendering the result and exiting the script. If Ajax is disabled, or there is no Ajax request to process, this method does nothing, so it is always safe to have it.


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:04:24 2010 for Common by  doxygen 1.5.6