DataTables warning (table id = 'employee_list'): Requested unknown parameter 0
DataTables warning (table id = 'employee_list'): Requested unknown parameter 0
richievc
Posts: 3Questions: 0Answers: 0
First off I want to say great plugin for jquery now on to the problem.
After hours of search I can not find any solution to this problem and it looks like that there is no real answer so with that said. I guess I just hoping here.
Any way here we go. The code is simple just doing a ajax call to a serive and return it as a json result for dat table to load only one result in the return json. by the way Im use codeigniter but cant find no reason that would make a difference
here is the code to ponder over.
Jquery Code:
[code]
$(document).ready( function() {
$('#employee_list').dataTable({
"bProcessing": true,
"bServerSide": true,
'sPaginationType': 'full_numbers',
"sAjaxSource": "<?php echo base_url(); ?>hr/human_resources/employee_data",
"aoColumns": [
{ "sName": "first_name"},
{ "sName": "last_name"},
{ "sName": "email"},
{ "sName": "is_active"},
{ "sName": "date_added"}
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} )
}
});
});
[/code]
The PHP COde:
[code]
/*
* Paging
*/
$sLimit = "";
if(isset( $_POST['iDisplayStart'] ) && $_POST['iDisplayLength'] != '-1') {
$sLimit = "LIMIT " . $_POST['iDisplayStart'] .", ".
$_POST['iDisplayLength'];
}
/*
* Ordering
*/
$sOrder = "";
$aColumns = array( 'first_name', 'last_name', 'email', 'is_active', 'date_added' );
if(isset( $_POST['iSortCol_0'] )) {
$sOrder = " ORDER BY ";
for($i=0 ; $i
After hours of search I can not find any solution to this problem and it looks like that there is no real answer so with that said. I guess I just hoping here.
Any way here we go. The code is simple just doing a ajax call to a serive and return it as a json result for dat table to load only one result in the return json. by the way Im use codeigniter but cant find no reason that would make a difference
here is the code to ponder over.
Jquery Code:
[code]
$(document).ready( function() {
$('#employee_list').dataTable({
"bProcessing": true,
"bServerSide": true,
'sPaginationType': 'full_numbers',
"sAjaxSource": "<?php echo base_url(); ?>hr/human_resources/employee_data",
"aoColumns": [
{ "sName": "first_name"},
{ "sName": "last_name"},
{ "sName": "email"},
{ "sName": "is_active"},
{ "sName": "date_added"}
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} )
}
});
});
[/code]
The PHP COde:
[code]
/*
* Paging
*/
$sLimit = "";
if(isset( $_POST['iDisplayStart'] ) && $_POST['iDisplayLength'] != '-1') {
$sLimit = "LIMIT " . $_POST['iDisplayStart'] .", ".
$_POST['iDisplayLength'];
}
/*
* Ordering
*/
$sOrder = "";
$aColumns = array( 'first_name', 'last_name', 'email', 'is_active', 'date_added' );
if(isset( $_POST['iSortCol_0'] )) {
$sOrder = " ORDER BY ";
for($i=0 ; $i
This discussion has been closed.
Replies
[code]
"aoColumns": [
{ "mDataProp": "first_name" },
{ "mDataProp": "last_name" },
{ "mDataProp": "email" },
{ "mDataProp": "is_active" },
{ "mDataProp": "date_added" }
],
[/code]
It used mDataProp instead of sName and it work if any body could explain why for informational purposes that would be great. Bu thope this helps someone when your json return objects instead of arrays
I make a function as workaround to this
[code]
/*
Manage null values in dataTables
*/
var nvl = function (param)
{
return function(data,type) {
return (data[param] == null ) ? "" : data[param];
} ;
};
[/code]
usage:
[code]
"aoColumns": [
{ "mDataProp": "first_name" },
{ "mDataProp": "last_name" },
{ "mDataProp": nvl("email") },
{ "mDataProp": "is_active" },
{ "mDataProp": "date_added" }
],
[/code]