dataTables support which format JSON?
dataTables support which format JSON?
The server-side is C #, MVC. the server returns the Json like this:
{
"sEcho": "1",
"iTotalRecords": 48,
"iTotalDisplayRecords": 48,
"aaData": [
{
"ID": "50",
"SN": "000111222350",
"RECEIVE_TIME": "2001/10/30 14:00:00",
"MSG_CONTENT": "abcdefg",
"MSG_TYPE": "1",
"MSG_SNEDER": "05",
"MSG_RECEVER": null
}
]
}
but datatables throws a warning:Requested unknown parameter '0' from the data source for row 0.
{
"sEcho": "1",
"iTotalRecords": 48,
"iTotalDisplayRecords": 48,
"aaData": [
{
"ID": "50",
"SN": "000111222350",
"RECEIVE_TIME": "2001/10/30 14:00:00",
"MSG_CONTENT": "abcdefg",
"MSG_TYPE": "1",
"MSG_SNEDER": "05",
"MSG_RECEVER": null
}
]
}
but datatables throws a warning:Requested unknown parameter '0' from the data source for row 0.
This discussion has been closed.
Replies
Check your markup columns and the data being sent back.
Columns should match. [/quote]
[code]"aoColumns": [
{ "sName": "ID" },
{ "sName": "SN" },
{ "sName": "RECEIVE_TIME" },
{ "sName": "MSG_CONTENT" },
{ "sName": "MSG_TYPE" },
{ "sName": "MSG_SENDER" },
{ "sName": "MSG_RECEVER" }
][/code]
The client and server defined column match..
How should `null` be displayed? An empty string usually, but `null !== ''` (unless you are Oracle). So you need to use the sDefaultContent option to tell DataTables what to do with null data.
Allan
"MSG_RECEVER": null[/quote]
I have set the default values in to the database, there is no null value in json, but the problem still occurs.
[code]{"sEcho":"1","iTotalRecords":48,"iTotalDisplayRecords":48,"aaData":[{"ID":"50","SN":"000111222350","RECEIVE_TIME":"2001/10/30 14:00:00","MSG_CONTENT":"23asdf134a","MSG_TYPE":"1","MSG_SNEDER":"05","MSG_RECEVER":"1"}}]}[/code]
Sometimes when you retrieve data from DB and it is NULL you have to set spaces ($tr [] = ' ' ) in your server side script before encoding and sending it back to the client to match an empty field on the markup
Sample code given below. Without complete information it is difficult to find a solution but hoping this might provide some help.
[code]
while($aDetailTxn = mysql_fetch_assoc($active_dtxn_result)) {
$tr = array();
foreach($aDetailTxn as $key => $value) {
if($key == 'TRANS_DETAIL_ID') {
$tr[] = $aDetailTxn['TRANS_DETAIL_ID'];
$tr[] = $aDetailTxn['TRANS_ID'];
$tr[] = $aDetailTxn['ACCOUNT_ID'];
$tr[] = $aDetailTxn['ACCOUNT_NAME'];
$invoiceDate = $oDate->getMysqldate2date($aDetailTxn['INVOICE_DATE']);
$tr[] = $invoiceDate;
$tr[] = $aDetailTxn['INVOICE_NUMBER'];
if(is_null($aDetailTxn['FROM_DATE']) && is_null($aDetailTxn['TO_DATE'])) {
$tr[] = ''; //This is what I described above
$tr[] = '';
} else {
$invoiceFromDate = $oDate->getMysqldate2date($aDetailTxn['FROM_DATE']);
$tr[] = $invoiceFromDate;
$invoiceToDate = $oDate->getMysqldate2date($aDetailTxn['TO_DATE']);
$tr[] = $invoiceToDate;
}
$tr[] = $aDetailTxn['AMOUNT'];
$tr[] = $aDetailTxn['REMARKS'];
}
}
$data['aaData'][] = $tr;
}
[/code]
[code]"aoColumns": [
{ "mData": "ID" },
{ "mData": "SN" },
{ "mData": "RECEIVE_TIME" },
{ "mData": "MSG_CONTENT" },
{ "mData": "MSG_TYPE" },
{ "mData": "MSG_SENDER" },
{ "mData": "MSG_RECEVER" }
][/code]
Now seems to have been solved. thanks girishmr and allan
[code]
{
{
"sEcho": "1",
"iTotalRecords": 48,
"iTotalDisplayRecords": 48,
"aaData": [
[
"50",
"000111222350",
"2001/10/30 14:00:00",
"23asdf134a",
"1",
"05",
"1"
]
]
}}
[/code]
And your JSON is of the following format. Fields are prefixed with the data. Something to do with your serverside script I hope.
[code]
{
"sEcho": "1",
"iTotalRecords": 48,
"iTotalDisplayRecords": 48,
"aaData": [
[
"ID": "50",
"SN": "000111222350",
"RECEIVE_TIME": "2001/10/30 14:00:00",
"MSG_CONTENT": "23asdf134a",
"MSG_TYPE": "1",
"MSG_SNEDER": "05",
"MSG_RECEVER": "1"
]
}
]
}
[/code]