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

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

the view with the datatable table:
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;link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" /&gt;
&lt;title&gt;DataTables example&lt;/title&gt;
&lt;style type="text/css" title="currentStyle"&gt;
@import "http://datatables.net/release-datatables/media/css/demo_page.css";
@import "http://datatables.net/release-datatables/media/css/demo_table.css";
&lt;/style&gt;
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function()
  {
    $('#example').dataTable
    ({
      'bServerSide'    : true,
      'sAjaxSource'    : '&lt;?=site_url("agents/ajax")?&gt;',
    });
  });
[removed]
&lt;/head&gt;
&lt;body id="dt_example"&gt;
<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>
&lt;/body&gt;
&lt;/html&gt;

the function ajax() in controller "agents" that is called in datatable init
Code:
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:
Code:
{"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

[eluser]virtualgadjo[/eluser]
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
Code:
'fnServerData'   : function(sSource, aoData, fnCallback){
$.ajax ({
  'dataType': 'json',
  'type'    : 'POST',
  'url'     : sSource,
  'data'    : aoData,
  'success' : fnCallback
});
}

last thing, be sure to change this
Code:
$sSearch = $this->ci->db->escape($this->ci->input->post('sSearch'));
into this
Code:
$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

[eluser]Sport_Billy[/eluser]
[quote author="virtualgadjo" date="1340179436"]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
Code:
'fnServerData'   : function(sSource, aoData, fnCallback){
$.ajax ({
  'dataType': 'json',
  'type'    : 'POST',
  'url'     : sSource,
  'data'    : aoData,
  'success' : fnCallback
});
}

last thing, be sure to change this
Code:
$sSearch = $this->ci->db->escape($this->ci->input->post('sSearch'));
into this
Code:
$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
[/quote]

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?


[eluser]phpstudent[/eluser]
where to download Datatables.php

[eluser]blagi[/eluser]
[quote author="phpstudent" date="1340952817"]where to download Datatables.php[/quote]

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

[eluser]phpstudent[/eluser]
hi

i am trying to do server side coding,


My Controller is

post.php

&lt;?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>
<b>Search Result</b>
</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


&lt;html&gt;
&lt;head&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/master.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/tables.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/iphone-check.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/icons.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;js/media/css/TableTools.css" type="text/css" /&gt;

[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]
&lt;/head&gt;
&lt;body&gt;



<div class="navigation_button" id='test_button'>Test DataTable with CL Framework</div>
<div class="content_area" id="target_area"></div>

&lt;/body&gt;

&lt;/html&gt;

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

[eluser]blagi[/eluser]
[quote author="phpstudent" date="1341059815"]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[/quote]

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.

[eluser]cryogenix[/eluser]
[quote author="phpstudent" date="1341059815"]hi

i am trying to do server side coding,


My Controller is

post.php

&lt;?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>
<b>Search Result</b>
</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


&lt;html&gt;
&lt;head&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/master.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/tables.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/iphone-check.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;css/icons.css"&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;js/media/css/TableTools.css" type="text/css" /&gt;

[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]
&lt;/head&gt;
&lt;body&gt;



<div class="navigation_button" id='test_button'>Test DataTable with CL Framework</div>
<div class="content_area" id="target_area"></div>

&lt;/body&gt;

&lt;/html&gt;

i am not getting the ouput... so any one can help me[/quote]

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/Ign...atatables/ and consult the wiki section there for usage guide.

[eluser]Unknown[/eluser]
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

[eluser]ηυмвєяσηє[/eluser]
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:
Code:
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/16...80/#956865
and your helper function will be like : http://ellislab.com/forums/viewthread/16...80/#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...filtering/

http://numberone.kodingen.com/datatables...iltering2/




Theme © iAndrew 2016 - Forum software by © MyBB