| tag
setName(), (*36)
This method sets a unique name that the column can be referenced by., (*37)
setGetMethod(), (*38)
This method lets DataTable_DataTable know where it should obtain the value for the current column. First, it
will check to see if this method exists within your DataTable_DataTable implementing class. Otherwise, it
will call the getter method on the entity object., (*39)
setSortKey(), (*40)
A key that loadData() can reference to know what to sort against., (*41)
Example:, (*42)
$column = new DataTable_Column();
$column->setName("browser")
->setTitle("Browser")
->setGetMethod("getBrowser")
->setSortKey("b.browser")
->setIsSortable(true);
DataTable_Request
An object of this class needs to be passed into the DataTable_DataTable->renderJson() method. This eventually gets
passed into your loadData() implementation. This object simply stores the parameters that are passed from DataTables
within AJAX requests and allow you to access them for pagination, sorting, and searching., (*43)
By default, this class provides a hydration method to fill the object with the parameters from a $_GET, $_POST, or
$_REQUEST array., (*44)
$request = new DataTable_Request();
$request->fromPhpRequest($_REQUEST);
You can extend this class to hydrate the parameters from some other framework specific request object if you need to., (*45)
DataTable_DataResult
This is the type of object that is expected to be returned from your DataTable_DataTable->loadData() implementation.
You just need to pass in the array of your entities and a count of the total number of results for pagination (total
records for all pages)., (*46)
Using your DataTable
Display table (index.php):, (*47)
// render the initial html/js
$table = new MyDataTable();
$table->setAjaxDataUrl('ajax.php');
echo $table->render();
Render AJAX response (ajax.php):, (*48)
// instatiate new DataTable
$table = new MyDataTable();
// convert DataTable AJAX parameters in request to a DataTable_Request
$request = new DataTable_Request();
$request->fromPhpRequest($_REQUEST);
// render the JSON data string
echo $table->renderJson($request);
Non-AJAX DataTable
If you have a smaller data set that you want to render in a DataTable and thus
don't need AJAX for your pagination, sorting you can easily switch to non-ajax mode., (*49)
You just need to make sure that serverSideEnabled is set to false on your DataTable_Config object., (*50)
This will result in your loadData() method getting called when DataTable_Datatable->render() is called. The
loadData() method will receive a DataTable_Request object which has the sorting set for whatever
the default sort column is within your config. You may also want to set the staticMaxLength on the
config object to let your loadData method know how to limit your results., (*51)
Example:, (*52)
// disable ajax
$config->setIsServerSideEnabled(false);
// let your loadData() method know to limit to 200 results
$config->setStaticMaxLength(200);
Multi-Column Sorting
If you need to sort against multiple columns, you can easily get the sorting information
of all of the columns from the DataTable_Request object., (*53)
Example:, (*54)
public function loadData(DataTable_Request $request)
{
foreach($request->getSortColumns() as $sortColIndex => $sortDir){
$sortKey = $this->getColumns()->get($sortColIndex)->getSortKey();
// do something with $sortKey and $sortDir
}
}
|