ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ignited DataTables

July 15, 2010 2:51am

Subscribe [119]
  • #1 / Jul 15, 2010 2:51am

    cryogenix

    90 posts

    Ignited Datatables is a wrapper class/library based on the native Datatables server-side implementation by Allan Jardine found at datatables[dot]net/examples/data_source/server_side.html for CodeIgniter

    FEATURES:

    1. Easy to use. Generates json using only a few lines of code.
    2. Support for table joins (left, right, outer, inner, left outer, right outer).
    3. Able to define custom columns, and filters.
    4. Editable custom variables with callback function support.

    RESOURCES:

    Fork: github[dot]com/IgnitedDatatables/Ignited-Datatables
    Wiki: github[dot]com/IgnitedDatatables/Ignited-Datatables/wiki

    Native PHP Version: github[dot]com/n1crack/IgnitedDatatables-native-php-version

    NOTES:

    ~ I have removed the download link here in favor of the regularly updated git repository
    ~ Sorry for the un-hyperlinked urls because the forums have gotten much stricter now =(

  • #2 / Jul 15, 2010 2:53am

    cryogenix

    90 posts

    CHANGELOG:
    07-29-11 : Version 0.6 includes some bug fixes and support for non utf-8 charsets.
    06-30-11 : Ignited Datatables v0.5.3 released, added mDataProp support for Datatables v1.8.1+
    05-31-11 : pushed v0.5 refactoring the source to use active record instead of native sql
    05-20-11 : launch of version 0.4 with a complete library overhaul in favor of method chaining and active record usage style
    05-08-11 : released version 0.3 with bug fixes and refactored codes
    04-11-11 : launch of Ignited Datatables version 0.2 with support for joins, custom columns, filters, and many more
    03-04-11 : started a git collab project with petroz for an improved library targeting joins and other new features
    10-12-10 : added initial draft for library version (no joins yet sobs…)
    10-04-10 : fixed minor bug for get_ordering as smcmillan pointed out.
    09-14-10 : added pointers on how to customize table results in the produce_output method of the datatables model.
    08-31-10 : added paging fix as loba suggested,
                    changed iTotal implementation in the model from “id” to $index since the default index can be any other column.
    07-26-10 : simplified json output implementation as audiopleb suggested.

  • #3 / Jul 21, 2010 6:12am

    johnwbaxter

    651 posts

    Instead of building the json in that crazy way it would make much more sense to just create an array with your values and..

    echo json_encode($your_array);
  • #4 / Jul 26, 2010 1:20am

    cryogenix

    90 posts

    post updated. thank you for your suggestion. *i initially only copy-pasted the given datatables code so i never really tinkered much on the code aside from the get switched to post

  • #5 / Jul 26, 2010 6:50am

    johnwbaxter

    651 posts

    No problem, it makes the code so much more readable too!

  • #6 / Aug 03, 2010 4:54am

    loba

    1 posts

    great posting here, cryogenix

    I just paste the code and its work perfect(almost), just one additional fix for get_pagging function on model, instead using ‘if’ only I add ‘else’ to make tables when loaded for the first time not display the whole records, it may looks like these:

    if($this->input->post(“iDisplayStart”) && $this->input->post(“iDisplayLength”) != “-1”)
          $sLimit = “LIMIT ” . $this->input->post(“iDisplayStart”) . “, ” . $this->input->post(“iDisplayLength”);
          else
          {
    $sLimit = "LIMIT " . "0" . ", " . $this->input->post("iDisplayLength");
    }

        return $sLimit;

    overall all other functions is working great, thank you for making post here

  • #7 / Aug 05, 2010 6:10am

    ruizpi

    7 posts

    I HAVE A PROBLEM WITH THIS COMPONENT. I WANT TO DO A SERVER SIDE GRID BUT IT DOESNT WORK.
    MY VIEW IS:

    <html >
    <head>
    <title><?php $titulo_pagina?></title>

    <link rel=“stylesheet” href=”../css/misclases.css” type=“text/css” />
    <link rel=“stylesheet” href=”../../../css/demo_table.css” type=“text/css” />
    <link rel=“stylesheet” href=”../../../css/demo_page.css” type=“text/css” />
    [removed][removed]
    [removed][removed]
    [removed]
          /*  $(document).ready(function() {
    $('#example').dataTable();

    } );*/
                    // This is a very simple demo that shows how a range of elements can
            // be paginated.
            // The elements that will be displayed are in a hidden DIV and are
            // cloned for display. The elements are static, there are no Ajax
            // calls involved.

            /**
            * Callback function that displays the content.
            *
            * Gets called every time the user clicks on a pagination link.
            *
            * @param {int} page_index New Page index
            * @param {jQuery} jq the container with the pagination links as a jQuery object
            */


            $(document).ready(function()
            {
    $('#example').dataTable
    ({
    "bProcessing" : true,
    "bServerSide" : true,
    "sAjaxSource" : "<?php echo base_url();?>ethyria/listener",
    "iDisplayStart" : 10,
    "fnServerData": function(sSource, aoData, fnCallback)
    {
    $.ajax(
    {
    'dataType': 'json',
    'type' : 'POST',
    'url' : sSource,
    'data' : aoData,
    'success' : fnCallback
    }
                      );
                  }

              });

              });
    [removed]


    </head>
      <body>
      <div id=“Contenedor”>
        <div id=“BarraIzq”>
        /images/logopine.png
        <?php echo br(3);?>
        <table align=“center” class=“MiTablaMenu”>
          <tr>
            <td class=“TDMenu”><font class=“MiFuenteTituloMenu”>MENU</font></td>
          </tr>
          <tr>
          <td class=“CeldaTransparente”><?php echo nbs(2);?></td>
          </tr>
          <tr>
            <td class=“TDMenu”>
              <?php
                $Opcion1 = “TAGSMCR”;
                echo anchor(’/ethyria/VerTagsMcr’,”<button type=‘submit’ class=‘MiBotonPine’>”.$Opcion1.”</button>”, array(‘class’ => ‘SinSubrayadoEnlace’));
              ?>
            </td>
          </tr>
          <tr>
            <td class=“TDMenu”>
              <?php
                $Opcion1 = “OPCION 2”;
                echo anchor(’/ethyria/VerTagsMcr’,$Opcion1,array(‘class’ =>‘MiBotonPine’));
              ?>
            </td>
          </tr>
          <tr>
            <td class=“TDMenu”>
              <?php
                $Opcion1 = “OPCION 3”;
                echo anchor(’/ethyria/VerTagsMcr’,$Opcion1,array(‘class’ =>‘MiBotonPine’));
              ?>
            </td>
          </tr>

        </table>
        </div>
        <div id=“BarraSup”>
          <font class=“MainFuente”>Ethyria Web Access</font>
        </div>
        <div id=“MarcoInterior”>

          <?php
          if (isset($consulta))
          {

    echo "<table id='example' class='display'>";
    echo "<thead>";
    echo "<tr><th>Obra</th><th>Id</th><th>Tagno</th><th>IdSistema</th><th>Descripcion</th>".
    "<th>Ubicación</th></tr>";
    echo "</thead>";

    echo "<tbody class='tipoletra'>";
    echo "<tr>";
    echo "<td colspan='5' class='dataTables_empty'>Loading data from server</td>";
    echo "</tr>";
    echo "</tbody>";
    echo "</table>";
    }
          ?>
        </div>
      </div>

    </body>
    </html>

    MY CONTROLLER:
        function VerTagsMcr()
        {
    /* $this->load->model('Ethmodel','',TRUE);
    $data['consulta'] = $this->Ethmodel->SacaTagsMcr();

    $this->load->view('v_view_menu',$data); */
    $this->load->model('Ethmodel','',TRUE);
    $data['consulta'] = $this->Ethmodel->SacaTagsMcr();
    $this->load->view('v_view_menu',$data);
    }
        public function listener()
        {
    $table = "tagsmcr";
    $columns = array("Obra","id", "IdSubSistema", "TagNo", "Descripcion","Ubicacion");
    $index = "id";
    $this->load->model("Datatables_model", "datatables");
    echo $this->datatables->generate($table, $columns, $index);
    }

  • #8 / Aug 05, 2010 10:52pm

    cryogenix

    90 posts

    erm could you at least tell us what the error(s) is/are so we could address your problem better?

    anyways for starters, have you ever tried datatables in native php without the CI framework? and if yes, did you get it to work? because if you got it to work, all it takes to port it to CI is:

    1. setup your listener in a controller (like in my controller example)
    2. copy the model i posted above
    3. point your sAjaxSource in your datatables script to the address of your listener

    keeping those 3 in check, your grid should work.

    ps:
    you might also want to wrap your posted codes in the “code” bb tag for readability

  • #9 / Aug 06, 2010 7:55am

    ruizpi

    7 posts

    Hi, again!
    It’s a pleasure to know that somebody can help to one. i will explain a little my problem. I have used this component with the server side example in my database and works well. I test it with your model and my controller and my view but it doesn´t show datas from my table.
    My view is like shows:

    <html >
    <head>
    <title><?php $titulo_pagina?></title>
    
    <link rel="stylesheet" href="../css/misclases.css" type="text/css" />
    <link rel="stylesheet" href="../../../css/demo_table.css" type="text/css" />
    <link rel="stylesheet" href="../../../css/demo_page.css" type="text/css" />
    [removed][removed]
    [removed][removed]
    [removed]
     $(document).ready(function()
            {
              $('#test').dataTable
              ({
                'bProcessing'    : true,
                'bServerSide'    : true,
                'sPaginationType': 'full_numbers',
                'sAjaxSource'    : '<?php echo base_url();?>ethyria/listener',
                'fnServerData': function(sSource, aoData, fnCallback)
                {
                  $.ajax
                  ({
                    'dataType': 'json',
                    'type'    : 'POST',
                    'url'     : sSource,
                    'data'    : aoData,
                    'success' : fnCallback
                  });
                }
              });
            });
    [removed]
    </head>
      <body>
        <div id="Contenedor">
         <div id="BarraIzq">
           /images/logopine.png
           <?php echo br(3);?>
           <table align="center" class="MiTablaMenu">
              <tr>
                <td class="TDMenu"><font class="MiFuenteTituloMenu">MENU</font></td>
              </tr>
              <tr>
              <td class="CeldaTransparente"><?php echo nbs(2);?></td>
              </tr>
              <tr>
                <td class="TDMenu">
                  <?php
                     $Opcion1 = "TAGSMCR";
                     echo anchor('/ethyria/VerTagsMcr',"<button type='submit' class='MiBotonPine'>".$Opcion1."</button>", array('class' => 'SinSubrayadoEnlace'));
                  ?>
                </td>
              </tr>
              <tr>
                <td class="TDMenu">
                  <?php
                     $Opcion1 = "OPCION 2";
                     echo anchor('/ethyria/VerTagsMcr',$Opcion1,array('class' =>'MiBotonPine'));
                  ?>
                </td>
              </tr>
              <tr>
                <td class="TDMenu">
                  <?php
                     $Opcion1 = "OPCION 3";
                     echo anchor('/ethyria/VerTagsMcr',$Opcion1,array('class' =>'MiBotonPine'));
                  ?>
                </td>
              </tr>
    
           </table>
         </div>
         <div id="BarraSup">
            <font class="MainFuente">Ethyria Web Access</font>
         </div>
         <div id="MarcoInterior">
              <table id="test" class="display">
              <thead>
                <tr>
                  <th>Id</th>
                  <th>Tagno</th>
                  <th>Descripcion</th>
                  <th>Ubicacion</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>loading…</td>
                </tr>
              </tbody>
            </table>
    
          </div>
        </div>
    
    </body>
    </html>

    My controller is:

    <?php
      class ethyria extends Controller{
    
          function __construct()
          {
              parent::Controller();
              $this->load->helper(array('html','form','url'));
              $this->load->helper('text');
              // es lo mismo que poner $this->load->helper(Array('html','form','url'));
              $this->load->library('form_validation');
          }
    
          function index()
          {
              $this->form_validation->set_rules('usuario','Nombre de usuario', 'required');
              $this->form_validation->set_rules('password','Contraseña', 'required|min_length[5]');
               // %s hace referencia al segundo parametro
              $this->form_validation->set_message('required', 'Debe introducir el campo %s');
              $this->form_validation->set_message('min_length', 'Campo %s demasiado corto');
              //    $this->form_validation->set_rules('EdUsuario','Alberto','required');
              //    $this->form_validation->set_rules('EdPassword','44038930','required');
    
              if ($this->form_validation->run()==FALSE)
              {
                  $this->load->view('v_login');
              }
              else
              {
                 $this->load->library('table');
                 $this->load->model('Ethmodel','',TRUE);
                 $usuario = $this->input->post('usuario');
                 $password = $this->input->post('password');
                 $TieneAcceso = $this->Ethmodel->Tiene_Acceso_Usuario($usuario,$password);
                 if ($TieneAcceso==TRUE)
                 {
                        $data['titulo_pagina']= 'Ethyria Web Access';
                        $this->load->view('v_view_menu',$data);
                 }
                 else
                        $this->load->view('v_login');
              }
          }
    
    
          function VerTagsMcr()
          {
             $this->load->model('Ethmodel','',TRUE);
             $data['consulta'] = $this->Ethmodel->SacaTagsMcr();
             $this->load->view('v_view_menu',$data);
           }
    
           public function listener()
           {
             $table = "tagsmcr";
             $columns = array("id","TagNo", "Descripcion", "Ubicacion");
             $index = "id";
             $this->load->model("Datatables_model", "datatables");
             echo $this->datatables->generate($table, $columns, $index);
           }
    
      }
    ?>

    I have attached a image what i see when i access to “tagsmcr” button.
    To be grateful to him for anticipated for his efforts for helping myself

  • #10 / Aug 08, 2010 2:39am

    cryogenix

    90 posts

    ok thank you for making your code more readable. your code seems fine. but it is still not clear to me what errors you are experiencing with it. although my guess is that your grid is not able to communicate with your listener. so anyways, are you familiar with using firebug? firebug can debug ajax responses very well and you can use it to get what your listener is having problems on. so unless you can give me that specific error, im afraid i can’t help you.

  • #11 / Sep 01, 2010 4:09am

    ruizpi

    7 posts

    hi, cryogenix. I discovered the problem that i have and i comment you, because it can happen to all. The code was correct. The problem was that my table in database have some fields with null value and the datatables version does´nt let null values. I changed the version of datatables and i discovered that my code worked well. it suppose a great surprising. Now i try to use querys instead of tables. Have you got any reference about it?.

  • #12 / Sep 14, 2010 12:27am

    cryogenix

    90 posts

    I’m not really sure what reference you are talking about but I did update the model regarding manipulation of data results and adding of other columns. I hope that can help you and others as well..

  • #13 / Sep 14, 2010 2:31am

    ruizpi

    7 posts

    The reference that i was talking is about how use a server side php for codeigniter using querys instead of tables. I modified a code that i founded and now i have codeigniter working with server side tables and querys.

  • #14 / Sep 15, 2010 7:23pm

    emorling

    66 posts

    If you get stuck with json_encode() returning null values, due to non-utf characters, then simply change this row.

    FROM:

    $aaData[$row_key][] = $col_val;


    TO:


    $aaData[$row_key][] = utf8_encode($col_val);

  • #15 / Sep 15, 2010 7:42pm

    emorling

    66 posts

    If you get stuck with json_encode() returning null values, due to non-utf characters, then simply change this row.

    FROM:

    $aaData[$row_key][] = $col_val;


    TO:


    $aaData[$row_key][] = utf8_encode($col_val);

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases