Problem with display of JSONarray using datatable
Problem with display of JSONarray using datatable
Testuser
Posts: 6Questions: 0Answers: 0
Hi all,
I am completely new to this plug-in, I am trying to display a JSonarray data returned by a servlet using the datatable plug-in, but with no result so far..I am getting weird java script error like..expected ; at 13456661 line number.
Please help me in fixing this..here is the data returned from server:
[code]
{"report":
{"rows":[
{"expDtTm":"","startTime":"","details":[{"startTime":"","status":"ACTIVE","query":"","queryDiffTime":"","engineId":461,"endTime":"","queryId":281}],"jobId":1400,"status":"QUEUED","description":"Basic Replication Dashboard Capture Log","link":"http:\/\/172.29.168.119\/stage\/2603\/1400","scheduledDtTm":"","frequency":"Immediate","endTime":"","jobDiffTime":"","jobInstanceId":2603},
]}}
[/code]
and similar rows..and I tried validating this JSON and its a valid json,
and in the .html page
[code]
$(document).ready(dataLoadAjax =
function(){
$.ajax({
"dataType":"jsonp",
"type":"GET",
"url":"http://localhost:8080/JobsServlet?do=view&output=json",
"jsonpCallback":"jsonpCallback",
"success":function(data){
}
});
});
function jsonpCallback(data){
$('#example').dataTable({
"bProcessing": true,
"bDestroy": true,
"bAutoWidth": false,
"aaData":data.report.rows,
"aoColumns":[{
"mDataProp":"jobInstanceId",
"mDataProp":"jobId",
"mDataProp":"description",
"mDataProp":"startTime",
"mDataProp":"endTime",
"mDataProp":"jobDiffTime",
"mDataProp":"status",
"mDataProp":"scheduledDtTm",
"mDataProp":"expDtTm",
"mDataProp":"frequency",
"mDataProp":"link"}]
}); }
[/code]
Please let me know if this is the correct approach or not...any help is appreciated.
thank u guys..
I am completely new to this plug-in, I am trying to display a JSonarray data returned by a servlet using the datatable plug-in, but with no result so far..I am getting weird java script error like..expected ; at 13456661 line number.
Please help me in fixing this..here is the data returned from server:
[code]
{"report":
{"rows":[
{"expDtTm":"","startTime":"","details":[{"startTime":"","status":"ACTIVE","query":"","queryDiffTime":"","engineId":461,"endTime":"","queryId":281}],"jobId":1400,"status":"QUEUED","description":"Basic Replication Dashboard Capture Log","link":"http:\/\/172.29.168.119\/stage\/2603\/1400","scheduledDtTm":"","frequency":"Immediate","endTime":"","jobDiffTime":"","jobInstanceId":2603},
]}}
[/code]
and similar rows..and I tried validating this JSON and its a valid json,
and in the .html page
[code]
$(document).ready(dataLoadAjax =
function(){
$.ajax({
"dataType":"jsonp",
"type":"GET",
"url":"http://localhost:8080/JobsServlet?do=view&output=json",
"jsonpCallback":"jsonpCallback",
"success":function(data){
}
});
});
function jsonpCallback(data){
$('#example').dataTable({
"bProcessing": true,
"bDestroy": true,
"bAutoWidth": false,
"aaData":data.report.rows,
"aoColumns":[{
"mDataProp":"jobInstanceId",
"mDataProp":"jobId",
"mDataProp":"description",
"mDataProp":"startTime",
"mDataProp":"endTime",
"mDataProp":"jobDiffTime",
"mDataProp":"status",
"mDataProp":"scheduledDtTm",
"mDataProp":"expDtTm",
"mDataProp":"frequency",
"mDataProp":"link"}]
}); }
[/code]
Please let me know if this is the correct approach or not...any help is appreciated.
thank u guys..
This discussion has been closed.
Replies
[code]
$(document).ready(dataLoadAjax =
function(){
var ajaxdata;
$.ajax({
"dataType":"jsonp",
"type":"GET",
"url":"
When i checked it in firefox..it shows a different error like ..it is pointing at the begining of the json string and says "not well formed" and the other one is "invalid label"..
can you tell me what does this mean and how to fix it..thank u
I got some info after google search and am able to fix those 2 warnings. but now a new problem started..the table is getting displayed but it has only one column..i.e only the data for the last column.."linlk" is getting displayed..not other data is comming..can u please tell me bow to get through this?..
thanku all
Allan
[code]
{
"report": {
"rows": [
{
"expDtTm": "",
"startTime": "",
"details": [
{
"startTime": "",
"status": "ACTIVE",
"query": "",
"queryDiffTime": "",
"engineId": 461,
"endTime": "",
"queryId": 281
}
],
"jobId": 1400,
"status": "QUEUED",
"description": "Basic Replication Dashboard Capture Log",
"link": "http://172.29.168.119/stage/2603/1400",
"scheduledDtTm": "",
"frequency": "Immediate",
"endTime": "",
"jobDiffTime": "",
"jobInstanceId": 2603
},
{
"expDtTm": "",
"startTime": "2011-12-01 13:29:06.0",
"details": [
{
"startTime": "2011-12-01 13:29:08.0",
"status": "READY",
"query": "",
"queryDiffTime": "0 hrs 0 mins 3 secs 3000 miliseconds",
"engineId": 541,
"endTime": "2011-12-01 13:29:11.0",
"queryId": 361
}
],
"jobId": 1480,
"status": "DELIVERED",
"description": "Test jib",
"link": "http://172.29.168.119/stage/2766/1480",
"scheduledDtTm": "",
"frequency": "Immediate",
"endTime": "2011-12-01 13:29:24.0",
"jobDiffTime": "0 hrs 0 mins 18 secs 18000 miliseconds",
"jobInstanceId": 2766
}
]
}
}
[/code]
and this is the html code:
[code]
$(document).ready(dataLoadAjax = function(){
var ajaxData;
$.ajax({
"dataType":"json",
"mimeType":"application/json",
"type":"GET",
"url":"http://localhost:8080/JobsServlet?do=view&output=json",
"success":function(data){
ajaxData = data;
$('#example').dataTable({
"bProcessing": true,
"bDestroy": true,
"bAutoWidth": false,
"aaData":ajaxData.report.rows,
"aoColumns":[{
"mDataProp":"jobInstanceId",
"mDataProp":"jobId",
"mDataProp":"description",
"mDataProp":"startTime",
"mDataProp":"endTime",
"mDataProp":"jobDiffTime",
"mDataProp":"status",
"mDataProp":"scheduledDtTm",
"mDataProp":"expDtTm",
"mDataProp":"frequency",
"mDataProp":"link",
"mDataProp":"details"}] ,
"fnServerData": fnServerObjectToArray(['jobInstanceId','jobId','description','startTime','endTime','jobDiffTime','status','scheduledDtTm','expDtTm','frequency','link','details']) }); } });
fnServerObjectToArray = function( aElements){
return function(sSource, a0Data,fnCallback){
$.ajax({
"dataType":'json',
"type":"post",
"url":sSource,
"data":a0Data,
"success": function(json){
var a =[];
for( var i=0, iLen = aaData.length; i< iLen; i++ ){
var inner = [];
for( var j=0, jLen = aElements.length; j>jLen ; j++){
inner.push(json.aaData[i][aElements[j]]);
}
a.push(inner);
}
json.aaData= a;
fnCallback(json); } }); } } });
[/code]
thanks for your help..
Actually - looking at it further, I don't see any need for fnServerData at all, since you aren't using DataTables' method to get the Ajax data - you are making your own call.
> the 10th column which is an object with properties gets dsiplayed as a hidden row..like user clicks any where on the row..the new row has to displayed below..with the data of the the 10th columns properties
You mean something like this: http://datatables.net/blog/Drill-down_rows ? You don't need a column for that. Just use fnGetData when you want to render the child row, and that will give you the data source object.
Allan
Now I got the actual problem..I am enclosing all mDataProps in a single [{"":"","":""}]..but the correct way is each one should have be seperately enclose [{},{},...] so only the final columns used to come..:)
But now got a new problem to display that inner drill down row..I follwed the example u mentioned..its quite understandable..great thanks for such a good article..but the problem is after I used that logic in my page..only table is getting displayed..on a white back ground all other formating,styles every thing is gone..not even the click for open and close of inner row is working...can u tell me wats the prob now?
Allan