Welcome Guest, Not a member yet? Register   Sign In
Ignited DataTables
#71

[eluser]dobbler[/eluser]
Just tried it on 1.7.3 and get the same error.. Argh!
#72

[eluser]cryogenix[/eluser]
your javascript code for your datatables may be at fault here because the php script is reporting that it is not getting the necessary parameters like sOrder in order for it to function properly. try building your datatables using native php 1st until you make it work. it would be easy to port it to CI by then.
#73

[eluser]ηυмвєяσηє[/eluser]
i got the same problem with dobbler

and fixed it.. replace functions below


from:
Code:
protected function get_display_data($table, $columns, $sWhere, $sOrder, $sLimit)
    {
      return $this->ci->db->query
      ('
        SELECT SQL_CALC_FOUND_ROWS ' . str_replace(" , ", " ", implode(", ", $columns)) . '
        FROM $table
        $sWhere
        $sOrder
        $sLimit
      ');
    }

To:
Code:
protected function get_display_data($table, $columns, $sWhere, $sOrder, $sLimit)
    {
      return $this->ci->db->query
      ('
        SELECT SQL_CALC_FOUND_ROWS ' . str_replace(" , ", " ", implode(", ", $columns)) . '
        FROM '.$table.'
        '.$sWhere.'
        '.$sOrder.'
        '.$sLimit.'
      ');
    }


from:

Code:
protected function get_total_data_set_length($table, $index, $sWhere)
    {
      return $this->ci->db->query
      ('
        SELECT COUNT(' . $index . ')
        FROM $table
        $sWhere
      ');
    }

to:
Code:
protected function get_total_data_set_length($table, $index, $sWhere)
    {
      return $this->ci->db->query
      ('
        SELECT COUNT(' . $index . ')
        FROM '.$table.'
        '.$sWhere.'
      ');
    }


and line 84 :
from
Code:
$iTotal = $aResultTotal[0]['COUNT($index)'];

to:
Code:
$iTotal = $aResultTotal[0]['COUNT('.$index.')'];



those are things that ive changed and it worked for me..
#74

[eluser]kunal doake[/eluser]
Hi,
Thanks for posting this artical.
I m new to CI.

I copied and pasted the datatable.php file in application/library folder.

I am not able to see the data in datatable. i can see only column headers, a search box, loading... and navigation button ie (prev, next first, last) displayed. same as below post by "ruizpi"... There r only 4 records and not any Null value in my table.

I checked with firebug and it displays 404 error. file not found on server.
when i check with var_dump page shows the json data
Code:
<?php
    var_dump($result);
?>

output =
Code:
string(265) "{"sEcho":0,"iTotalRecords":"4","iTotalDisplayRecords":"4","aaData":[["1","kunal","b33a46f5ee81f6f0790f3ea9f02468e1"],["2","datta","3f7aaf2ae8456b2256cfe6825597c3ec"],["3","rajan","d66c264e1dbd73e6111d3ffc70908e8e"],["7","arati","13dd520baf6553c263452508a9d04ad8"]]}"

my controller is as follows - "mast_crud.php"

Code:
<?php
  class Mast_crud extends CI_Controller{
    var $base;
    var $css;
    var $js;
    var $images;
    
      function __consturct()      {
        parent::CI_Controller();
        
                  
      }
      function index(){
          echo('crud');
      }
      
      function party_master(){
        
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $this->js = $this->config->item('js');
        
        $data['base'] = $this->base;
        $data['css'] = $this->css;
        $data['js'] = $this->js;
        
        $table = "user_master";
        $columns = array("user_id", "user_name","password");
        $index = "user_id";
        
        $this->load->library('Datatable');
        $data["result"] = $this->datatable->generate($table ,$columns ,$index );
        $this->load->view('crud_party_mast',$data);
      }
      
      function user_master(){
          echo("user master");[removed]nullo();
      }
      
      function port_master(){
          echo("port_master");
      }
      
  }
  
  
?>

my view is as follow - "crud_party_mast.php"

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Menu&lt;/title&gt;
&lt;meta name="Author" content="Stu Nicholls" /&gt;
&lt;base href="&lt;?php echo("$base");?&gt;"&gt;
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo("$base$css");?&gt;/pro_dropdown_3.css" /&gt;
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo("$base$css");?&gt;/demo_table.css" /&gt;
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo("$base$css")?&gt;/Mycss.css "&gt;
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function()
  {
    $('#test').dataTable
    ({
      'bServerSide'    : true,
      'bAutoWidth'     : false,
      'sPaginationType': 'full_numbers',
      'aoColumns'      :
      [
        null,
        null,
        null
      ],  
      'sAjaxSource'    : '&lt;?php echo($base);?&gt;mast_crud/party_master',
      'fnServerData': function(sSource, aoData, fnCallback)
      {
        $.ajax
        ({
          'dataType': 'json',
          'type'    : 'POST',
          'url'     : sSource,
          'data'    : aoData,
          'success' : fnCallback
        });
      }
    });
    
  });
[removed]
&lt;/head&gt;

&lt;body&gt;

<div id="dt_example">
  <table id="test" class="display">
    <thead>
      <tr>
        <th>ID</th>
        <th>Name</th>
        <th>password</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>loading...</td>
      </tr>
    </tbody>
  </table>
</div>
&lt;?php
    var_dump($result);
?&gt;
&lt;/body&gt;
&lt;/html&gt;

Thanks in advance
#75

[eluser]ηυмвєяσηє[/eluser]
try this
Code:
&lt;?php
  class Mast_crud extends CI_Controller{
    var $base;
    var $css;
    var $js;
    var $images;
    
      function __consturct()      {
        parent::CI_Controller();
        
                  
      }
      function index(){
          echo('crud');
      }
      
      function party_master(){
        
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $this->js = $this->config->item('js');
        
        $data['base'] = $this->base;
        $data['css'] = $this->css;
        $data['js'] = $this->js;
        
        $table = "user_master";
        $columns = array("user_id", "user_name","password");
        $index = "user_id";
        
        $this->load->library('Datatable');
        $data["result"] = $this->datatable->generate($table ,$columns ,$index );
        //$this->load->view('crud_party_mast',$data);
        echo $data["result"];    
      }
      
      function user_master(){
          echo("user master");[removed]nullo();
      }
      
      function port_master(){
          echo("port_master");
      }
      
  }
  
  
?&gt;
#76

[eluser]dobbler[/eluser]
[quote author="ηυмвєяσηє" date="1301155048"]i got the same problem with dobbler

and fixed it.. replace functions below


from:
Code:
protected function get_display_data($table, $columns, $sWhere, $sOrder, $sLimit)
    {
      return $this->ci->db->query
      ('
        SELECT SQL_CALC_FOUND_ROWS ' . str_replace(" , ", " ", implode(", ", $columns)) . '
        FROM $table
        $sWhere
        $sOrder
        $sLimit
      ');
    }

To:
Code:
protected function get_display_data($table, $columns, $sWhere, $sOrder, $sLimit)
    {
      return $this->ci->db->query
      ('
        SELECT SQL_CALC_FOUND_ROWS ' . str_replace(" , ", " ", implode(", ", $columns)) . '
        FROM '.$table.'
        '.$sWhere.'
        '.$sOrder.'
        '.$sLimit.'
      ');
    }


from:

Code:
protected function get_total_data_set_length($table, $index, $sWhere)
    {
      return $this->ci->db->query
      ('
        SELECT COUNT(' . $index . ')
        FROM $table
        $sWhere
      ');
    }

to:
Code:
protected function get_total_data_set_length($table, $index, $sWhere)
    {
      return $this->ci->db->query
      ('
        SELECT COUNT(' . $index . ')
        FROM '.$table.'
        '.$sWhere.'
      ');
    }


and line 84 :
from
Code:
$iTotal = $aResultTotal[0]['COUNT($index)'];

to:
Code:
$iTotal = $aResultTotal[0]['COUNT('.$index.')'];



those are things that ive changed and it worked for me..[/quote]


Great! Didn't have my brain on right to think of that.. But I'm still having an error with sOrder being undefined..
Quote:Message: Undefined variable: sOrder

Filename: libraries/Datatables.php

Line Number: 143

Also I'm confused about the view call in the sample controller

Code:
$this->load->view('ajax', $data);

Should I create a blank view called "ajax.php" or should I make this view the name of the view I'm displaying the table in? Or do I have to leave it named "ajax" for the javascript to hook into??

Would appreciate if you could post your controller and views so I can see exactly how you've set it up, I think I just have a block with it.

Thanks for your help!

Rob.

ps. here is my setup:

Controller dtest.php (the listener):
Code:
&lt;?php if(!defined("BASEPATH")) exit("No direct script access allowed");
  class Dtest extends Controller
  {
    public function __construct()
    {
      parent::__construct();
    }

    public function listener()
    {
      $table = "eml_emails";
      $columns = array("EmailId", "Subject", "Added");
      $index = "EmailId";
      $this->load->library("Datatables");
      $data['result'] = $this->datatables->generate($table, $columns, $index);
      $this->load->view('ajax', $data);
    }
  }
?&gt;

My page function "get_sent_mails.php":
Code:
function get_sent_mails()
    {    
        $data['page_title'] = "Email Centre";

        $this->load->view('sent_mails_view3', $data);
        
        
    }


My view "sent_mails_view3.php":
Code:
&lt;html &gt;
&lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /&gt;
    &lt;title&gt;Email Centre&lt;/title&gt;
    
    [removed][removed]

    [removed][removed]
    [removed][removed]
    [removed][removed]
    [removed][removed]
    [removed][removed]
    [removed][removed]
    [removed][removed]
    
    &lt;link  href="&lt;?= base_url(); ?&gt;css/datatables.css" rel="stylesheet" type="text/css" /&gt;

    &lt;link  href="&lt;?= base_url(); ?&gt;css/insttable.css" rel="stylesheet" type="text/css" /&gt;
    [removed]
      $(document).ready(function()
      {
        $('#test').dataTable
        ({
          'bServerSide'    : true,
          'bAutoWidth'     : false,
          'sPaginationType': 'full_numbers',
          'sAjaxSource'    : '&lt;?= base_url(); ?&gt;dtest/listener',
          'aoColumns'      :
          [
            {
              'bSearchable': false,
              'bVisible'   : false
            },
            null,
            null,
            null
          ],
          'fnServerData': function(sSource, aoData, fnCallback)
          {
            $.ajax
            ({
              'dataType': 'json',
              'type'    : 'POST',
              'url'     : sSource,
              'data'    : aoData,
              'success' : fnCallback
            });
          }
        });
      });
    [removed]
&lt;/head&gt;
&lt;body&gt;

<div id="dt_example">
  <table id="test" class="display">
    <thead>
      <tr>
        <th>id</th>
        <th>Date</th>
        <th>Subject</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>loading...</td>
      </tr>
    </tbody>
  </table>
</div>

&lt;/body&gt;
&lt;/html&gt;

So I'm sure from that you can tell where my brain has taken a left turn on this.. I'm definitely not seeing it right..
#77

[eluser]ηυмвєяσηє[/eluser]
1. go to line 143. check the line and be sure u write $sOrder instead of sOrder

2. replace
Code:
//$this->load->view('ajax', $data);  // no need
echo $data['result'];  // try this
3. thats it.. it should work
#78

[eluser]dobbler[/eluser]
[quote author="ηυмвєяσηє" date="1301201732"]1. go to line 143. check the line and be sure u write $sOrder instead of sOrder

2. replace
Code:
//$this->load->view('ajax', $data);  // no need
echo $data['result'];  // try this
3. thats it.. it should work[/quote]

YESS!!!!! Thank you!!!! Line 143 was fine it was the output of the ajax that was screwing me up.

Again, thank you, you've saved my ass!

Rob.
#79

[eluser]kunal doake[/eluser]
after using
Code:
echo $data["result"];
i got only Json string prited on screen.
datatable view is not loaded.
#80

[eluser]cryogenix[/eluser]
that is because you need to feed that result to your datatables ajax caller.




Theme © iAndrew 2016 - Forum software by © MyBB