Пример #1
0
 * 
 * Look at ajax.php to see how the data is pulled for the table. By default it is configured
 * to load the data from a CSV file using the CsvBrowserService. This can be switched to use
 * the DbBrowserService which will load the data from a MySQL database. This demonstrates
 * how your DataTable doesn't need to be tied to any specific database implementation, etc.
 * Thus, you can use your application's existing ORM, services, etc. to deal with the data 
 * and your DataTable doesn't need to care about where the data came from as long as it's
 * provided an array of entity objects.
 */
// register the DataTable autoloader
include '../src/DataTable/Autoloader.php';
spl_autoload_register(array('DataTable_Autoloader', 'autoload'));
// include the Demo DataTable class
include 'DemoDataTable.php';
// instantiate the DataTable
$table = new DemoDataTable();
// set the url to the ajax script
$table->setAjaxDataUrl('ajax.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
	
	<title>php-datatables Demo</title>

	<style type="text/css" title="currentStyle">
		@import "DataTables-1.8.1/media/css/demo_table.css";
	</style>
Пример #2
0
 *  
 * This demonstrates how your DataTable doesn't need to be tied to any specific database implementation, etc.
 * Thus, you can use your application's existing ORM, services, etc. to deal with the data 
 * and your DataTable doesn't need to care about where the data came from as long as it's
 * provided an array of entity objects.
 */
// register the DataTable autoloader
include '../src/DataTable/Autoloader.php';
spl_autoload_register(array('DataTable_Autoloader', 'autoload'));
// include the Demo DataTable class
include_once 'DemoDataTable.php';
// define the Browser Service to use for this demo
// either 'db' or 'csv'
define('SERVICE_TO_USE', 'csv');
// build a Browser Service object based on the type that was selected
if (SERVICE_TO_USE == 'db') {
    include_once 'DbBrowserService.php';
    $browserService = new DbBrowserService('localhost', 'browsers', 'root', '');
} elseif (SERVICE_TO_USE == 'csv') {
    include_once 'CsvBrowserService.php';
    $browserService = new CsvBrowserService('data/browsers.csv');
}
// instatiate new DataTable
$table = new DemoDataTable();
// set selected Browser Service to the demo DataTable
$table->setBrowserService($browserService);
// 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);