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

[eluser]HiTek[/eluser]
Use CODE tag in square brackets or use Post Reply instead of Fast Reply.
#52

[eluser]Gizmo84[/eluser]
Thanks for that.

Here is my view.

Code:
<html>
<head>
<title>Welcome to CodeIgniter</title>

<!--<link type="text/css" rel="stylesheet" href="css/demo_table.css" />-->
<link type="text/css" rel="stylesheet" href="<?php echo asset_url() ?>css/smoothness/jquery-ui-1.8.2.custom.css" />
<link type="text/css" rel="stylesheet" href="<?php echo asset_url() ?>css/styles.css" />


[removed][removed]
[removed][removed]

</head>

<body>

<div id="dt_example">
  <table id="drivers" class="display">
    <thead>
      <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Address</th>
        <th>Town</th>
        <th>Postcode</th>
        <th>Phone</th>
        <th>Email</th>
        <th>Driver No.</th>
        <th>Badge No.</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>loading...</td>
      </tr>
    </tbody>
  </table>
</div>
[removed]
  $(document).ready(function()
  {
    $('#drivers').dataTable
    ({
      'bProcessing'    : true,
      'bServerSide'    : true,
      'bAutoWidth'     : false,
      'sPaginationType': 'full_numbers',
      'sAjaxSource'    : '&lt;?=base_url();?&gt;welcome/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;/body&gt;
&lt;/html&gt;


My Controller

Code:
&lt;?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
        $this->load->helper(array('html', 'text'));
                $this->load->library('form_validation');        
    }
    
    function index()
    {
        /* $this->load->model('M_drivers');    
        $data['drivers'] = $this->M_drivers->getAll(); */
        $this->load->view('welcome_message');
    }
    
    public function listener()
    {
        $table = "drivers";
        $columns = array("id", "name", "address", "town", "postcode", "phone", "email", "driverNo", "badgeNo");
        $index = "id";
        $this->load->library("Datatables");
        echo $this->datatables->generate($table, $columns, $index);
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
#53

[eluser]HiTek[/eluser]
ok. Take a look at that piece of code.

Code:
'aoColumns'      :
      [
        {
          'bSearchable': false,
          'bVisible'   : false
        },
        null,
        null,
        null
      ]

Please, notice that you defined here only 4 columns while your controller returns 9. Add 5 more null.
#54

[eluser]Gizmo84[/eluser]
Works a treat Thank you, can't believe I was being so blind to it LOL Smile
#55

[eluser]cryogenix[/eluser]
o yes do take note of the number of nulls or simply how you define aoColumms. keep in mind that they should reflect the same number of columns as what was defined in your controller.

I didn't mention this in my guide as I was basing the assumption of complete or very good understanding of the datatables library beforehand.
#56

[eluser]cipmang[/eluser]
hi all, please help me....
i am newbie...

why the output of mine like this :

{"sEcho":0,"iTotalRecords":"57","iTotalDisplayRecords":"57","aaData":[["Trident","Internet Explorer 4.0","Win 95+","4","X"],["Trident","Internet Explorer 5.0","Win 95+","5","C"],["Trident","Internet Explorer 5.5","Win 95+","5.5","A"],["Trident","Internet Explorer 6","Win 98+","6","A"],["Trident","Internet Explorer 7","Win XP SP2+","7","A"],["Trident","AOL browser (AOL desktop)","Win XP","6","A"],["Gecko","Firefox 1.0","Win 98+ \/ OSX.2+","1.7","A"],["Gecko","Firefox 1.5","Win 98+ \/ OSX.2+","1.8","A"],["Gecko","Firefox 2.0","Win 98+ \/ OSX.2+","1.8","A"],["Gecko","Firefox 3.0","Win 2k+ \/ OSX.3+","1.9","A"]]}

it has right output, but the datatable doesnt work... why ?
what i must do?
#57

[eluser]cipmang[/eluser]
i have follow cryogenix's steps, but why the output like that...

my controller :

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('forbidden city');

class Main extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }
    
    public function listener()
    {
      $table = "ajax";
      $columns = array("engine", "browser", "platform", "version", "grade");
      $index = "id";
      $this->load->library("Datatables");
      echo $this->datatables->generate($table, $columns, $index);
    }

}

my view :

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
        &lt;title&gt;DataTables example&lt;/title&gt;
        &lt;?php echo link_tag('assets/DataTabript" src="&lt;?php echo base_url().'assets/DataTables/media/js/jquery.js'; ?&gt;">[removed]
        [removed][removed]
        [removed]
          $(document).ready(function()les/media/css/demo_page.css'); ?&gt;
        &lt;?php echo link_tag('assets/DataTables/media/css/demo_table.css'); ?&gt;
        [removed]
    &lt;/head&gt;
    &lt;body&gt;
        <div id="dt_example">
          <table id="test" class="display">
            <thead>
              <tr>
                <th>Engine</th>
                <th>Browser</th>
                <th>Platform</th>
                <th>Version</th>
                <th>Grade</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>loading...</td>
              </tr>
            </tbody>
          </table>
        </div>        
    &lt;/body&gt;
&lt;/html&gt;

and i use his library,
help me please....
#58

[eluser]cipmang[/eluser]
i am sorry, my view like this:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
        &lt;title&gt;DataTables example&lt;/title&gt;
        &lt;?php echo link_tag('assets/DataTables/media/css/demo_page.css'); ?&gt;
        &lt;?php echo link_tag('assets/DataTables/media/css/demo_table.css'); ?&gt;
        [removed][removed]
        [removed][removed]
        [removed]
          $(document).ready(function()
          {
            $('#test').dataTable
            ({
              'bServerSide'    : true,
              'bAutoWidth'     : false,
              'sPaginationType': 'full_numbers',
              'sAjaxSource'    : '&lt;?=base_url();?&gt;main/listener',
              'aoColumns'      :
              [
                {
                  'bSearchable': false,
                  'bVisible'   : false
                },
                null,
                null,
                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>Engine</th>
                <th>Browser</th>
                <th>Platform</th>
                <th>Version</th>
                <th>Grade</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>loading...</td>
              </tr>
            </tbody>
          </table>
        </div>        
    &lt;/body&gt;
&lt;/html&gt;
#59

[eluser]cryogenix[/eluser]
not sure what problems you're getting but have you tried using datatables for non-CI projects before? i'm not really good with helping other peoples woes with using my library but my best advise for you is to try and make a static version first not using CI. if you can setup one which works properly, you can then port them easily to CI.
#60

[eluser]cipmang[/eluser]
thanks for your reply,....
can you explain, why in the function listener doesnt use $this->load->view......




Theme © iAndrew 2016 - Forum software by © MyBB