Valid Json is loading but table still empty using codeigniter php class.
Valid Json is loading but table still empty using codeigniter php class.
Hi guys,
I'm following up an earlier question with this because the prior question was marked as having an accepted answer ( I think accidently ):
I'm working with the jquery datatables plugin and codeigniter , while trying to follow (roughly ) http://www.ahmed-samy.com/php-codeigniter-full-featrued-jquery-datatables-part-1/. I am getting the following error:
DataTables warning: table id=big_table - Requested unknown parameter '0' for row 0. For more information about this error, please see http://datatables.net/tn/4
In firebug there are no errors and the following valid JSON is returned: http://pastebin.com/sNPYqdrn I checked using http://jsonlint.com/. The table itself its empty.
How can I fix this?
Thanks in advance,
Bill
My controller:
function index()
{
//set table id in table open tag
$tmpl = array('table_open' => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="mytable">');
$this->table->set_template($tmpl);
$this->table->set_heading("id,message_id,subject,date");
$this->load->view('serversidetestview');
}
//function to handle callbacks
function datatable()
{
$this->datatables->select("id,message_id,subject,date")->from('imap');
echo $this->datatables->generate();
}
My view:
<html>
<head>
<base href="<?=base_url();?>">
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.1/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.1/js/jquery.dataTables.min.js"></script>
</head>
<body>
<h1>Subscriber management</h1>
<?php echo $this->table->generate(); ?>
</div>
<script type="text/javascript">
$(document).ready(function () {
var oTable = $('#big_table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": 'datatable_controller/datatable',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ": 20,
"fnInitComplete": function () {
oTable.fnAdjustColumnSizing();
},
'fnServerData': function (sSource, aoData, fnCallback) {
$.ajax
({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
}
});
});
</script>
</body>
</html>
This question has an accepted answers - jump to answer
Answers
It may be a simple copy/paste error on your part, but in the pastebin that you linked, the object is missing the initial
{
Thank you , Yes that was a copy and paste error, I tested the original Json as described above and it passed. - Bill
So... problem solved or... problem still exists?
Unfortunately the problem is not solved.
Perhaps it is because you haven't labeled the columns according to the data?
Have you tried putting this in the options?
Only a guess as I haven't used objects as my data source before...
Also, what does the HTML markup look like after the call to:
html>
<head>
<base href="http://localhost/b1/">
</head>
<body>
<thead>
$(document).ready(function () { var oTable = $('#big_table').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": 'datatable_controller/datatable', "sPaginationType": "full_numbers", // "iDisplayStart ": 20, // "oLanguage": { // "sProcessing": "" // }, "columns": [ { "data": "id" }, { "data": "message_id" }, { "data": "subject" }, { "data": "date" } ] "fnInitComplete": function () { oTable.fnAdjustColumnSizing(); }, 'fnServerData': function (sSource, aoData, fnCallback) { $.ajax ({ 'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback }); } }); });<tr>
<th>id</th><th>message_id</th><th>subject</th><th>date</th></tr>
</thead>
</table>
</body>
</html>
or try: http://pastebin.com/tWPRMGBn
May or may not be an issue, but line 45 of your pastbin is missing a comma after the
]
Ah, new thought! I didn't have a quick way to test this with JSON per se... but I did create a localized test here on live.datatables.net (demo)
Here's a copy of the most relevant parts (note the comments near the end):
So it may be that you need to only send the array of objects? And remove the
draw
,recordsTotal
, andrecordsFiltered
fields? Or perhaps somehow tell DT to ignore them?Rhino, Thank you very much for sticking with it. You were correct, it was the comma after line 45. I've been working on this for days, so much appreciated.
Best Regards,
Bill
thanks, also works for me, though not served filtering, any idea what this doing wrong
@kontramundo I'd suggest making a new post detailing the issue you are having, and linking back to this post, if you feel it provides context to your problem
Solved Thanks.
kontramundo, what was the solution?