Hey thanks for the quick reply,
Yeah I have tried that, but all the JS looks fine it is doing a count for the aoColumns to create the iColumns param. I was hoping someone had a similar problem with this library to help narrow it down.
Cheers
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
July 15, 2010 2:51am
Subscribe [119]#46 / Jan 14, 2011 4:54am
Hey thanks for the quick reply,
Yeah I have tried that, but all the JS looks fine it is doing a count for the aoColumns to create the iColumns param. I was hoping someone had a similar problem with this library to help narrow it down.
Cheers
#47 / Jan 14, 2011 4:56am
Have you tried to remove the parameter? I’m 90% sure the problem is somewhere in JS.
#48 / Jan 14, 2011 6:24am
I don’t think its a JS problem, I changed to the most up to date version of DataTables JS and still nothing, all the information is being passed to the view but DataTables can’t show it based on this column count.
If I change the AJAX type from post to get I don’t get the error but it still does not show the data, in both post and get the response has all the data! I don’t know if the php isn’t passing the right column count properly!
#49 / Jan 14, 2011 6:42am
I see. It’s hard to say what is wrong without the code.
#50 / Jan 14, 2011 6:45am
ok i’ll send my code. Quick question how to I wrap my code in a post?
#51 / Jan 14, 2011 6:48am
Use CODE tag in square brackets or use Post Reply instead of Fast Reply.
#52 / Jan 14, 2011 6:52am
Thanks for that.
Here is my view.
<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' : '<?=base_url();?>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]
</body>
</html>
My Controller
<?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 / Jan 14, 2011 6:57am
ok. Take a look at that piece of 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 / Jan 14, 2011 7:12am
Works a treat Thank you, can’t believe I was being so blind to it LOL 😊
#55 / Jan 15, 2011 12:07pm
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 / Feb 16, 2011 4:27am
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 / Feb 16, 2011 4:31am
i have follow cryogenix’s steps, but why the output like that…
my controller :
<?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 :
<!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" />
<title>DataTables example</title>
<?php echo link_tag('assets/DataTabript" src="<?php echo base_url().'assets/DataTables/media/js/jquery.js'; ?>">[removed]
[removed][removed]
[removed]
$(document).ready(function()les/media/css/demo_page.css'); ?>
<?php echo link_tag('assets/DataTables/media/css/demo_table.css'); ?>
[removed]
</head>
<body>
<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>
</body>
</html>and i use his library,
help me please….
#58 / Feb 16, 2011 4:59am
i am sorry, my view like this:
<!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" />
<title>DataTables example</title>
<?php echo link_tag('assets/DataTables/media/css/demo_page.css'); ?>
<?php echo link_tag('assets/DataTables/media/css/demo_table.css'); ?>
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function()
{
$('#test').dataTable
({
'bServerSide' : true,
'bAutoWidth' : false,
'sPaginationType': 'full_numbers',
'sAjaxSource' : '<?=base_url();?>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]
</head>
<body>
<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>
</body>
</html>#59 / Feb 16, 2011 5:27am
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 / Feb 16, 2011 5:43am
thanks for your reply,....
can you explain, why in the function listener doesnt use $this->load->view…...