using datatables with php and zend framework
using datatables with php and zend framework
I would like to integrate datatables with my zend framework application. Has anyone done this before, and if so would you be able to give me any pointers?
Should the initial html generate the first page of data in the table, then subsequent requests use ajax calls?
Or should the initial html just have an empty table and use javascript to generate an ajax request for the first page of data?
I'm just really not sure where to start because i have not used datatables before, and am fairly new to zend framework as well.
Should the initial html generate the first page of data in the table, then subsequent requests use ajax calls?
Or should the initial html just have an empty table and use javascript to generate an ajax request for the first page of data?
I'm just really not sure where to start because i have not used datatables before, and am fairly new to zend framework as well.
This discussion has been closed.
Replies
At present the first html request returns all the records in the table (this inital request with no specific search params returns appox 10,000 records, ouch!) When they finally return, data tables works nicely with pagination locally on the client. However, this is obvoiusly not the way to do it.
The first request should only fetch say 15 records (assuming 15 records per page). Then i want to use ajax with datatables to return more records as required by pagination.
I don't understand how datatables knows how many more records are available.
Should i just return an empty table on the first request, and then get datatables to make an initial ajax request to fetch to total number of records and the first page? Or can i somehow feed datatables with the total number of records and the records per page along with the first page of data fetched by the inital html request?
I'm probably not making any sense.
(i'm pulling records from a mySQL (or Firebird) database.
I think I give you a help.
can you tell me how to start with the implementation of datatables in a zend framework project?
can you share any code perhaps?
something like this:
controller:
[code]<?php
class ExampleController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
$this->view->headTitle()->append('Example');
//populate database tables
$example = new Application_Model_ExampleMapper();
$this->view->entries = $example->fetchAll();
}
}[/code]
view:
[code]
$(document).ready(function() {
$('#example').dataTable();
} );
ID
Field1
Field2
Field3
<?php foreach ($this->entries as $entry): ?>
<?php echo $this->escape($entry->ID) ?>
<?php echo $this->escape($entry->field1) ?>
<?php echo $this->escape($entry->field2) ?>
<?php echo $this->escape($entry->field3) ?>
<?php endforeach ?>
[/code]