EllisLab text mark
Advanced Search
23 of 30
23
   
Ignited DataTables
Posted: 18 June 2012 12:15 PM   [ # 341 ]   [ Rating: 0 ]
Joined: 2012-06-17
3 posts

echo prints result on the page as follows:
{“sEcho”:0,“iTotalRecords”:2,“iTotalDisplayRecords”:2,“aaData”:[[“1”,“23096720”,“MIHIR”,“mihir.parekh@abc.com”,“1”],[“2”,“12345”,“Mihir”,“abc@gmail.com”,“1”]],“sColumns”:“id,username,name,email,login_count”}

The table just displays processing…

My controller

function user_management_edit(){
   
  $this
->load->library('Datatables');
  
$this->datatables->select('id , username , name , email , login_count');
  
$this->datatables->from('user');
  echo 
$this->datatables->generate();
  
//$mytable = $this->datatables->generate();
  //echo ($mytable);
  //$this->load->view('user_management_edit');
  //$data['result'] = $this->datatables->generate();
   
$data['main_content''user_management_edit';
   
$this->load->view('Template'$data);
  
  
  

My View

<section class="grid_12">
    <
div class="box">
      <
div class="title"><span class="icon16_sprite i_spreadsheet"></span>Data table</div>
      <
p><a href="[removed]void(0);">Click to add a new row</a></p>
      <
div class="inside">
<
table cellpadding="0" cellspacing="0" border="0" class="display" id="test">
 <
thead>
  <
tr>
   <
th width="10%">Id</th>
   <
th width="20%">Username</th>
   <
th width="25%">Name</th>
   <
th width="25%">Email</th>
   <
th width="20%">Login Count</th>
  </
tr>
 </
thead>
 <
tbody>
  <
tr>        
   <
td colspan="5" class="dataTables_empty">Loading data from server</td>
   </
tr>
 </
tbody>
</
table>
   </
div>
   
  </
div>
 </
section

My Template initializing script

[removed]
  
$(document).ready(function() {
  
$('#test').dataTable{
   
   
"bProcessing"true,
     
"bServerSide"true,
     
"sServerMethod""POST",
     
"sPaginationType""full_numbers",
     
"bDeferRender"true,
     
"sAjaxSource""<?php echo base_url(); ?>index.php/home/user_management_edit",
     
"aoColumns"
           
[
      { 
'sName' 'id' },
      
'sName' 'username' },
      
'sName' 'name' },
      
'sName' 'email' },
      
'sName' 'login_count' }
           ]
,
     
"fnServerData": function ( sSourceaoDatafnCallback 
    
{
     
$.ajax{
      
"dataType""json",
      
"type""POST",
      
"url"sSource,
      
"data"aoData,
      
"success"fnCallback,
      
);
    

   } 
);
  
);
  
[removed] 

Please help me solve this issue

 

 
Posted: 19 June 2012 05:43 AM   [ # 342 ]   [ Rating: 0 ]
Joined: 2010-09-25
7 posts

concat is not working on select

select("id, CONCAT('first_name', ' ', 'last_name') as name"); 
 
Posted: 19 June 2012 07:42 AM   [ # 343 ]   [ Rating: 0 ]
Joined: 2012-02-15
4 posts

Hi!!
I have a problem with this useful library.
My situation as follows.
Datatables library in application/libraries

the view with the datatable table:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<
html>
<
head>
<
meta http-equiv="content-type" content="text/html; charset=utf-8" />
<
link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" />
<
title>DataTables example</title>
<
style type="text/css" title="currentStyle">
@
import "http://datatables.net/release-datatables/media/css/demo_page.css";
@
import "http://datatables.net/release-datatables/media/css/demo_table.css";
</
style>
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function()
  
{
    
$('#example').dataTable
    
({
      
'bServerSide'    true,
      
'sAjaxSource'    '<?=site_url("agents/ajax")?>',
    
});
  
});
[removed]
</head>
<
body id="dt_example">
<
div id="container">
<
h1>Ignited Datatables</h1>
  <
table border="0" cellpadding="4" cellspacing="0" class="display" id="example">
    <
thead>
      <
tr>
        <
th width="10%">Name</th>
        <
th width="10%">Surname</th>
      </
tr>
    </
thead>
    <
tbody>
      <
tr>
        <
td>loading...</td>
      </
tr>
    </
tbody>
  </
table>
</
div>
</
body>
</
html

the function ajax() in controller “agents” that is called in datatable init

function ajax(){
  $this
->datatables
  
->select('name, surname'
    ->
from('agents');
  echo  
$this->datatables->generate() ;
 

The problem is that table rows does not show up.
if I access directly to the function ajax(), the output is:

{"sEcho":0,"iTotalRecords":5,"iTotalDisplayRecords":5,"aaData":[["Piero","Maltesino"],["Piero","Maltese"],["piero","Maltese"],["prova","prova"],["Piero","Maltese"]],"sColumns":"name,surname"

that seems to be correct.

Firebug and chrome tools does not show any error.

If I use native php ignitedDatatable, it works correctly.
Any idea?
Thanks smile

 
Posted: 20 June 2012 04:03 AM   [ # 344 ]   [ Rating: 0 ]
Joined: 2011-03-24
22 posts

hi,

@sport_billy
sorry to be a little late to answer…
may be you could try with ‘bProcessing’ set to true + “sServerMethod”  : “POST”

then, as you’re using ajax source, you may need to add the function

'fnServerData'   : function(sSourceaoDatafnCallback){
 
$.ajax ({
  
'dataType''json',
  
'type'    'POST',
  
'url'     sSource,
  
'data'    aoData,
  
'success' fnCallback
 }
);

last thing, be sure to change this

$sSearch $this->ci->db->escape($this->ci->input->post('sSearch')); 

into this

$sSearch $this->ci->input->post('sSearch'); 

line 290 in the librairy as the former line double escapes data and generates an sql syntax error (ci active record already escapes data)

have swing

 
Posted: 27 June 2012 08:00 AM   [ # 345 ]   [ Rating: 0 ]
Joined: 2012-05-31
8 posts
virtualgadjo - 20 June 2012 04:03 AM

hi,

@sport_billy
sorry to be a little late to answer…
may be you could try with ‘bProcessing’ set to true + “sServerMethod”  : “POST”

then, as you’re using ajax source, you may need to add the function

'fnServerData'   : function(sSourceaoDatafnCallback){
 
$.ajax ({
  
'dataType''json',
  
'type'    'POST',
  
'url'     sSource,
  
'data'    aoData,
  
'success' fnCallback
 }
);

last thing, be sure to change this

$sSearch $this->ci->db->escape($this->ci->input->post('sSearch')); 

into this

$sSearch $this->ci->input->post('sSearch'); 

line 290 in the librairy as the former line double escapes data and generates an sql syntax error (ci active record already escapes data)

have swing

Hello and thanks again very much for your help..i made all of the changes you suggested but still nothing shows up if i set “bServerSide”: TRUE

Have you managed to make it work?

If so, can you please give me a sample of your code that works so i can test it?

 

 
Posted: 29 June 2012 02:53 AM   [ # 346 ]   [ Rating: 0 ]
Joined: 2012-06-29
2 posts

where to download Datatables.php

 
Posted: 29 June 2012 08:57 AM   [ # 347 ]   [ Rating: 0 ]
Joined: 2011-04-19
7 posts
phpstudent - 29 June 2012 02:53 AM

where to download Datatables.php

https://github.com/IgnitedDatatables/Ignited-Datatables

 
Posted: 30 June 2012 08:36 AM   [ # 348 ]   [ Rating: 0 ]
Joined: 2012-06-29
2 posts

hi

i am trying to do server side coding,


My Controller is

post.php

<?php
class post Extends CI_Controller{
function __construct()
  {
      parent::__construct();

  }

function index() {
      $this->load->view(‘main’);
  }
  function listener() {
      $table = ‘post’;
      $columns = array(‘title’, ‘category’, ‘post_date’,‘add_time’);
      $index = ‘id’;
      $this->load->library(‘Datatables’);

      $data[‘result’] = $this->datatables->generate($table, $columns, $index);
      echo $data[‘result’];

  }
  function test() {
      $this->load->view(‘test’);
  }

==========*********==========


and View is

test.php

[removed]
$(document).ready(function(){
  $(’#test_table’).dataTable({
      ‘bServerSide’  : true,
      ‘bAutoWidth’    : false,
      ‘sPaginationType’: ‘full_numbers’,
      ‘sAjaxSource’: ‘post/listener’,
      ‘aoColumns’ : [
        { ‘sName’: ‘title’},
        { ‘sName’: ‘category’},
        { ‘sName’: ‘post_date’},
        { ‘sName’: ‘add_time’ },
      ],
      ‘fnServerData’: function(sSource, aoData, fnCallback){
        $.ajax({
          ‘dataType’: ‘json’,
          ‘type’: ‘POST’,
          ‘url’: sSource,
          ‘data’: aoData,
          ‘success’: fnCallback
        });
      },
  });
});
[removed]

<fieldset>
  <legend>
      Search Result
  </legend>
  <table cellpadding=“0” cellspacing=“0” border=“0” class=“display” id=‘test_table’>
      <thead>
        <tr class=“odd gradeX”>
          <th>Title</th>
          <th>Category</th>
          <th>Post Date</th>
          <th>Added Date</th>
        </tr>
      </thead>
      <tbody>
      <tr>                     
          <td>loading..</td> 
        </tr> 
      </tbody>
      <tfoot>
        <tr>
          <th>Title</th>
          <th>Category</th>
          <th>Post Date</th>
          <th>Added Date</th>
        </tr>
      </tfoot>
  </table>
</fieldset> 

=======*********=======

main.php


<html>
<head>
<link rel=“stylesheet” href=”<?php echo base_url()?>css/master.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>css/tables.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>css/iphone-check.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>css/icons.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>js/media/css/TableTools.css” type=“text/css” />
 
[removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
 
  [removed]
$(document).ready(function(){

//$.post(“http://localhost/dt_sample/index.php/post/test”,function(data){
  $.post(‘post/test’, function(data){
      $(’#target_area’).html(data);
  });
});
[removed]
</head>
<body>

<div class=“navigation_button” id=‘test_button’>Test DataTable with CL Framework</div>
<div class=“content_area” id=“target_area”></div> 

</body>

</html>

i am not getting the ouput… so any one can help me

 
Posted: 02 July 2012 10:03 AM   [ # 349 ]   [ Rating: 0 ]
Joined: 2011-04-19
7 posts
phpstudent - 30 June 2012 08:36 AM

hi

i am trying to do server side coding,


My Controller is

post.php

....

i am not getting the ouput… so any one can help me

The best way to debug such errors is by using Firefox Firebug or Webkit development tools. There is a “Net” tab within which you can see what your server side function returns: either data or some html with errors.

 
Posted: 04 July 2012 10:49 PM   [ # 350 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-15
91 posts
phpstudent - 30 June 2012 08:36 AM

hi

i am trying to do server side coding,


My Controller is

post.php

<?php
class post Extends CI_Controller{
function __construct()
  {
      parent::__construct();

  }

function index() {
      $this->load->view(‘main’);
  }
  function listener() {
      $table = ‘post’;
      $columns = array(‘title’, ‘category’, ‘post_date’,‘add_time’);
      $index = ‘id’;
      $this->load->library(‘Datatables’);

      $data[‘result’] = $this->datatables->generate($table, $columns, $index);
      echo $data[‘result’];

  }
  function test() {
      $this->load->view(‘test’);
  }

==========*********==========


and View is

test.php

[removed]
$(document).ready(function(){
  $(’#test_table’).dataTable({
      ‘bServerSide’  : true,
      ‘bAutoWidth’    : false,
      ‘sPaginationType’: ‘full_numbers’,
      ‘sAjaxSource’: ‘post/listener’,
      ‘aoColumns’ : [
        { ‘sName’: ‘title’},
        { ‘sName’: ‘category’},
        { ‘sName’: ‘post_date’},
        { ‘sName’: ‘add_time’ },
      ],
      ‘fnServerData’: function(sSource, aoData, fnCallback){
        $.ajax({
          ‘dataType’: ‘json’,
          ‘type’: ‘POST’,
          ‘url’: sSource,
          ‘data’: aoData,
          ‘success’: fnCallback
        });
      },
  });
});
[removed]

<fieldset>
  <legend>
      Search Result
  </legend>
  <table cellpadding=“0” cellspacing=“0” border=“0” class=“display” id=‘test_table’>
      <thead>
        <tr class=“odd gradeX”>
          <th>Title</th>
          <th>Category</th>
          <th>Post Date</th>
          <th>Added Date</th>
        </tr>
      </thead>
      <tbody>
      <tr>                     
          <td>loading..</td> 
        </tr> 
      </tbody>
      <tfoot>
        <tr>
          <th>Title</th>
          <th>Category</th>
          <th>Post Date</th>
          <th>Added Date</th>
        </tr>
      </tfoot>
  </table>
</fieldset> 

=======*********=======

main.php


<html>
<head>
<link rel=“stylesheet” href=”<?php echo base_url()?>css/master.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>css/tables.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>css/iphone-check.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>css/icons.css”>
  <link rel=“stylesheet” href=”<?php echo base_url()?>js/media/css/TableTools.css” type=“text/css” />
 
[removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
  [removed][removed]
 
  [removed]
$(document).ready(function(){

//$.post(“http://localhost/dt_sample/index.php/post/test”,function(data){
  $.post(‘post/test’, function(data){
      $(’#target_area’).html(data);
  });
});
[removed]
</head>
<body>

<div class=“navigation_button” id=‘test_button’>Test DataTable with CL Framework</div>
<div class=“content_area” id=“target_area”></div> 

</body>

</html>

i am not getting the ouput… so any one can help me

hi there, sorry for the late reply but the version of IgnitedDatatables you are using has long been outdated and is kind of deprecated. you may get the latest version on out github page at: https://github.com/IgnitedDatatables/Ignited-Datatables/ and consult the wiki section there for usage guide.

 Signature 

Ignited Datatables

 
Posted: 16 July 2012 03:47 AM   [ # 351 ]   [ Rating: 0 ]
Joined: 2012-03-05
1 posts

Hi There,

I am using datatables in admin panel.

I had one issue with this.

Can you please tell me how to modify data before displaying it. or before passing it to the client as json data.

For Example: in my table created and modify date is there which i want to display in another format say total seconds to may be and GMT or human readable form,

Another Example: suppose i have path or name of the image into database table now i want to display it as image with img and a tag.

Can you please tell me how can i do this..

Thanks

 
Posted: 16 July 2012 11:51 AM   [ # 352 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-26
111 posts

Hi Vaibhav,

1. Date parsing :

You have two option:

a. run sql command to get modified date.
 
run: 
SELECT DATE_FORMAT(column_name, ‘%d/%m/%Y’) as myNewDate FROM tablename

or simply:

public function test() {
        $this
->load->library('Datatables');
        
$this->datatables
                
->select("column1, DATE_FORMAT(column_name, '%d/%m/%Y') as colum2")
                ->
from('table')
        
$data['result'$this->datatables->generate();
        echo 
$data['result'];

b. Make a helper file and run a callback function with edit function like this : http://ellislab.com/forums/viewthread/160896/P280/#956865
and your helper function will be like : http://ellislab.com/forums/viewthread/160896/P280/#956911


2. same solution with 1. 


some examples for native version of the library. You can adapt this for codeigniter. see differences between date columns

http://numberone.kodingen.com/datatables/examples/multi_filtering/

http://numberone.kodingen.com/datatables/examples/multi_filtering2/

 

 Signature 

Ignited Datatables
Nested Sets

 
Posted: 18 July 2012 11:46 AM   [ # 353 ]   [ Rating: 0 ]
Joined: 2012-06-25
1 posts

great library! thanks!

 
Posted: 19 July 2012 12:11 PM   [ # 354 ]   [ Rating: 0 ]
Joined: 2011-12-13
3 posts

Thanks! The first suggestion fixed my woes, however instead of the second change:

$sSearch = $this->ci->db->escape($this->ci->input->post(‘sSearch’));

for

$sSearch = $this->ci->input->post(‘sSearch’);

laxdoctor - 30 May 2012 04:25 PM

DiLer - I’m having the same exact problem. When I directly access my controller that produces the json I see the correct data output. I was also able to get it to work when I set bServerSide to false.

EDIT 2: I made two changes to get this to work.

First, set add “sServerMethod”: “POST” so your script looks something like:

$(document).ready(function() {
 
$('#test_table').dataTable{
  
"bProcessing"true,
  
"bServerSide"true,
  
"sServerMethod""POST",
  
"sAjaxSource""/index.php/tables/listener"
 
);
); 

Second, change Line 295 of the datatables library

From:

if($sSearch != ''

To:

if($sSearch != && $sSearch != ''
 
Posted: 23 July 2012 10:51 AM   [ # 355 ]   [ Rating: 0 ]
Joined: 2011-03-24
22 posts

hi,

in case it helps anybody here, i’ve made a little change in the get_paging function

protected function get_paging()
{
 $iStart 
$this->ci->input->post('iDisplayStart');
 
$iLength $this->ci->input->post('iDisplayLength');
 if ( 
$iLength != '-1' )
 
{
  $this
->ci->db->limit($iLength != '' $iLength 100, ($iStart)? $iStart 0);
 
}

the former function prevented the -1 (see all) trick from working, limiting the result amount to 100
of course, to be used cautiously if ever you deal with 100,000 + rows table (i often have to…)

have swing

 
23 of 30
23