Parsing server side return JSON
Parsing server side return JSON
Hello, I am getting the following error; I suspect it is in my JS code and has not reached the execution of the JSON returned (however I am attaching a valid response from the server). Any help appreciated. Thanks.
Error stack -
jquery.dataTables.js:5570 Uncaught TypeError: Cannot read property 'style' of undefined
at _fnCalculateColumnWidths (jquery.dataTables.js:5570)
at _fnInitialise (jquery.dataTables.js:4693)
at loadedInit (jquery.dataTables.js:1320)
at HTMLTableElement.<anonymous> (jquery.dataTables.js:1332)
at Function.each (jquery-2.2.4.js:365)
at jQuery.fn.init.each (jquery-2.2.4.js:137)
at jQuery.fn.init.DataTable [as dataTable] (jquery.dataTables.js:869)
at jQuery.fn.init.$.fn.DataTable (jquery.dataTables.js:15134)
at HTMLDocument.<anonymous> (lidarSaas.html:37)
at fire (jquery-2.2.4.js:3187)
_fnCalculateColumnWidths @ jquery.dataTables.js:5570
_fnInitialise @ jquery.dataTables.js:4693
loadedInit @ jquery.dataTables.js:1320
(anonymous) @ jquery.dataTables.js:1332
each @ jquery-2.2.4.js:365
each @ jquery-2.2.4.js:137
DataTable @ jquery.dataTables.js:869
$.fn.DataTable @ jquery.dataTables.js:15134
(anonymous) @ lidarSaas.html:37
fire @ jquery-2.2.4.js:3187
fireWith @ jquery-2.2.4.js:3317
ready @ jquery-2.2.4.js:3536
completed @ jquery-2.2.4.js:3552
Here is my server-side JS :
$(document).ready(function() {
$('#lidarSaas').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "http://127.0.0.1:8000/lidarSaas/",
"dataType" :"json",
"dataSrc": "",
},
"columns": [
{ "data": "id" },
{ "data": "title" },
{ "data": "uploadTimestamp" },
{ "data": "uploadFileNameS3" },
{ "data": "processedTimestamp" },
{ "data": "processedFileNameS3" },
{ "data": "status" },
{ "data": "processingTime" },
{ "data": "owner" },
]
} );
} );
Here is my sample JSON (validated) -
[{
"id": 1,
"title": "KGP 63",
"uploadTimestamp": "2017-03-19T10:22:11.560084Z",
"uploadFileNameS3": "/mysamples_data/uploads/S3/abc_def_1.las",
"processedTimestamp": "2017-03-19T10:22:11.560208Z",
"processedFileNameS3": "/mysamples_data/processed/S3/abc_def_processed_color.las",
"status": "Processed",
"processingTime": 10,
"owner": "Prasad"
}, {
"id": 2,
"title": "KGP 63",
"uploadTimestamp": "2017-03-19T10:23:51.392700Z",
"uploadFileNameS3": "/mysamples_data/uploads/S3/abc_def_1.las",
"processedTimestamp": "2017-03-19T10:23:51.392745Z",
"processedFileNameS3": "/mysamples_data/processed/S3/abc_def_processed_color.las",
"status": "Processed",
"processingTime": 10,
"owner": "Prasad"
}, {
"id": 3,
"title": "KGP 63",
"uploadTimestamp": "2017-03-19T10:23:51.474415Z",
"uploadFileNameS3": "/mysamples_data/uploads/S3/abc_def_3.las",
"processedTimestamp": "2017-03-19T10:23:51.474458Z",
"processedFileNameS3": "",
"status": "Uploading",
"processingTime": 0,
"owner": "Prasad"
}, {
"id": 4,
"title": "KGP 63",
"uploadTimestamp": "2017-03-19T10:23:51.552371Z",
"uploadFileNameS3": "/mysamples_data/uploads/S3/abc_def_6.las",
"processedTimestamp": "2017-03-19T10:23:51.552414Z",
"processedFileNameS3": "",
"status": "Processing",
"processingTime": 0,
"owner": "Prasad"
}, {
"id": 5,
"title": "KGP 63",
"uploadTimestamp": "2017-03-19T10:23:51.637871Z",
"uploadFileNameS3": "/mysamples_data/uploads/S3/abc_def_4.las",
"processedTimestamp": "2017-03-19T10:23:51.638028Z",
"processedFileNameS3": "",
"status": "Upload aborted",
"processingTime": 0,
"owner": "Prasad"
}, {
"id": 6,
"title": "KGP 63",
"uploadTimestamp": "2017-03-19T10:23:51.707202Z",
"uploadFileNameS3": "/mysamples_data/uploads/S3/abc_def_2.las",
"processedTimestamp": "2017-03-19T10:23:51.707245Z",
"processedFileNameS3": "",
"status": "Uploaded",
"processingTime": 0,
"owner": "Prasad"
}]
Here is my HTML -
Title | Source File | Upload date | Status | Processed File | Processed date | Processing Time | Owner |
---|
This question has accepted answers - jump to:
Answers
Looks like you defined 9 columns in Datatables but have 8 in the HTML. I think you need to define a column for
id
and hide it usingcolumns.visible
.Kevin
For just not define it in the columns array. Just because it is in the data set doesn't mean you need to use it.
Allan
Thanks guys it worked.