using datatables with php and zend framework

using datatables with php and zend framework

srayner02srayner02 Posts: 15Questions: 0Answers: 0
edited November 2010 in General
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.

Replies

  • OraraOrara Posts: 4Questions: 0Answers: 0
    No fear when adding datatables in a zend framework project. Just follow the the steps as in a normal projetc and everything will go alright. Paste the media folder of datatable in the public Directory of your project and append necessary files in the top of your html code as you do with normal javascript files. After this configurations, just follow the step according to the functionality you want to implement.
  • srayner02srayner02 Posts: 15Questions: 0Answers: 0
    I have it working to a degree, but still need to do some work with pagination.

    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.
  • OraraOrara Posts: 4Questions: 0Answers: 0
    If just for displaying the rest of the table data you don't need any ajax synchronisation. Just Specify the number of data that you want the table to display and paginate through the numbers. For more on pagination setting just consult the Defining length menu option of the datatable examples that came with the library.
    I think I give you a help.
  • theSpartantheSpartan Posts: 1Questions: 0Answers: 0
    srayners02 or orara, or someone else:
    can you tell me how to start with the implementation of datatables in a zend framework project?
    can you share any code perhaps?
  • arunadlarunadl Posts: 1Questions: 0Answers: 0
    can any one post the code
  • technoicontechnoicon Posts: 12Questions: 0Answers: 0
    edited May 2012
    what i have done so far is to just use zend to display a table. you'll have to figure out your own database mapper. but hopefully you go that down pat. if not, just ask.

    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]
This discussion has been closed.