json is correct but the table is not showing
json is correct but the table is not showing
Hi Allan,
I'm using ASP.Net and modified example for ASP.Net from the datatables.com.I'm not getting any errors but the table is not showing up. The JSON is valid based on http://jsonlint.com. Thanks.
The script:
$(document).ready(function() {
$('#myDataTable').dataTable({
"bJQueryUI": true,
"bPaginate": true,
"bLengthChange": true,
//"bFilter": true,
//"bStateSave": true,
"bSort": true,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 10,
"sAjaxSource": "DataTableServer1.aspx",
"aoColumns": [
{ "sTitle": "CIN", "sWidth": "20%", "bSortable": "true" },
{ "sTitle": "SSN", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "CaseNumber", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "LName", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "FName", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "RecordID", "sWidth": "40%", "bSortable": "true" }
],
"aaSorting": [[1, 'asc']],
"oLanguage": {
"sLengthMenu": "Page length: _MENU_",
"sSearch": "Filter:",
"sZeroRecords": "No matching records found"
},
"sPaginationType": "full_numbers",
"fnServerData": function(sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
// "success": function(msg) {
// //alert(msg.d);
// fnCallback(msg.d);
// }
});
}
});
});
HTML:
CIN
SSN
CaseNumber
LName
Fname
RecordID
The output JSON:
{"sEcho": 1,"iTotalRecords": 68,"iTotalDisplayRecords": 10,"aaData": [["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"]]}
I'm using ASP.Net and modified example for ASP.Net from the datatables.com.I'm not getting any errors but the table is not showing up. The JSON is valid based on http://jsonlint.com. Thanks.
The script:
$(document).ready(function() {
$('#myDataTable').dataTable({
"bJQueryUI": true,
"bPaginate": true,
"bLengthChange": true,
//"bFilter": true,
//"bStateSave": true,
"bSort": true,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 10,
"sAjaxSource": "DataTableServer1.aspx",
"aoColumns": [
{ "sTitle": "CIN", "sWidth": "20%", "bSortable": "true" },
{ "sTitle": "SSN", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "CaseNumber", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "LName", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "FName", "sWidth": "40%", "bSortable": "true" },
{ "sTitle": "RecordID", "sWidth": "40%", "bSortable": "true" }
],
"aaSorting": [[1, 'asc']],
"oLanguage": {
"sLengthMenu": "Page length: _MENU_",
"sSearch": "Filter:",
"sZeroRecords": "No matching records found"
},
"sPaginationType": "full_numbers",
"fnServerData": function(sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
// "success": function(msg) {
// //alert(msg.d);
// fnCallback(msg.d);
// }
});
}
});
});
HTML:
CIN
SSN
CaseNumber
LName
Fname
RecordID
The output JSON:
{"sEcho": 1,"iTotalRecords": 68,"iTotalDisplayRecords": 10,"aaData": [["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"]]}
This discussion has been closed.
Replies
Thanks,
Allan
By the way am I correct that if I get this JSON output in the Response subtab of the Console tab in the Firebug then this JSON is returned to the datatables on the client side and supposed to be displayed?
There is another interesting thing. Everything that is supposed to show above the content of the data table(search box, column names with the mouse cursor changing to hand when hover on the column name to allow sorting) is displayed. The page FirstPreviousNextLast are displayed under the column names.
Below is the info from Firebug
Post tab:
bRegex false
bRegex_0 false
bRegex_1 false
bRegex_2 false
bRegex_3 false
bRegex_4 false
bRegex_5 false
bSearchable_0 true
bSearchable_1 true
bSearchable_2 true
bSearchable_3 true
bSearchable_4 true
bSearchable_5 true
bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
bSortable_4 true
bSortable_5 true
iColumns 6
iDisplayLength 10
iDisplayStart 0
iSortCol_0 1
iSortingCols 1
mDataProp_0 0
mDataProp_1 1
mDataProp_2 2
mDataProp_3 3
mDataProp_4 4
mDataProp_5 5
sColumns
sEcho 1
sSearch
sSearch_0
sSearch_1
sSearch_2
sSearch_3
sSearch_4
sSearch_5
sSortDir_0 asc
Source
sEcho=1&iColumns=6&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&mDataProp_5=5&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true
Response:
{"sEcho": 1,"iTotalRecords": 68,"iTotalDisplayRecords": 10,"aaData": [["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"]]}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
HTML tab:
{"sEcho": 1,"iTotalRecords": 68,"iTotalDisplayRecords": 10,"aaData": [["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"],["KKKKK","111-11-1111","44444444","AAA","AAA","1111"]]}
The other thing to note is that iTotalRecords and iTotalDisplayRecords should be the same unless you have filtering applied - which you don't in this case - so they should both be 68.
Allan