The Most basic Question of them All: Row 0 Column 0 error.
The Most basic Question of them All: Row 0 Column 0 error.
I am getting a row 0 column 0 error. Help.
And here is a sample of the JSON I've created:
{"draw" : 1,"recordsTotal" : 57 ,"data": [["Daisy","Gold","1366528127","","-","","-","","MD",""]]}
Here is my configuration:
$('#TableId').DataTable(
{
"columnDefs": [
{ "width": "5%", "targets": [0] },
{ "className": "text-center custom-middle-align", "targets": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
],
pageLength:100,
"scrollY": "400px",
"scrollCollapse": true,
"language":
{
"processing": "<div class='overlay custom-loader-background'><i class='fa fa-cog fa-spin custom-loader-color'></i></div>"
},
"processing": true,
"serverSide": true,
"ajax":
{
"url": "/Plugin/GetData",
"type": "POST",
"dataType": "JSON"
},
"columns": [
{ "data": "FirstName" },
{ "data": "LastName" },
{ "data": "NPI" },
{ "data": "FMFID" },
{ "data": "FMFNasalBone" },
{ "data": "NTQRID" },
{ "data": "NTQRNasalBone" },
{ "data": "MiddleName" },
{ "data": "Suffix" },
{ "data": "Comments" }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
});
});
This question has an accepted answers - jump to answer
Answers
I tried to use this as an example:
https://datatables.net/examples/data_sources/ajax.html
Looks like you are returning array based data but have defined Datatables to use object based data with
columns.data
. Take a look here:https://datatables.net/manual/data/#Data-source-types
Maybe try removing your columns definition.
You may have removed it but your returned JSON is missing
recordsFiltered
. Check out this doc for more info:https://datatables.net/manual/server-side#Returned-data
Kevin
Yup! Exactly what Kevin says.
If you do want to use
columns.data
, then you need to return an array of objects indata
, not an array of arrays (sincedata: 'FirstName'
is meaningless in an array).Allan
Thanks for your reply.
Here's what I've tried:
This is one record in the database. I have tried to totally eliminate arrays.
And my Error:
DataTables warning: table id=TableId - Ajax error. For more information about this error, please see http://datatables.net/tn/7
If you follow the details at the tech note that the error message links to, what does it show? That's normally a server issue, and you'd need to check the server's error logs.
Allan
Did you follow the troubleshooting steps at the link provided in the error?
The link starts with:
Are you receiving something other than a 2XX response?
Also you probably don't need
"dataSrc": "data"1 since that is the default. You need to use the
-option ajax.dataSrcoption if the data returned is not in an object called
data. If you are just returning an array of objects then you will need
"dataSrc" : ""`.Are you returning the data in an array of objects as shown here:
https://datatables.net/manual/data/#Objects
Kevin
This is what I'm getting in my Response.
<!DOCTYPE html>
<html>
<head>
<title>Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
@media screen and (max-width: 639px) {
pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
}
@media screen and (max-width: 479px) {
pre { width: 280px; }
}
</style>
</head>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
[InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.]
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +85
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +64
System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +347
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult) +52
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +10System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +22System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9987265
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
</pre></code>
</html>
Ignore the previous. This is an example of what I'm getting back...
{"draw":1,"recordsTotal":24999,"recordsFiltered":24999,"data":{"Content":"{\"FirstName\":\"Nancy\",\"LastName\":\"Sims\",\"NPI\":\"1366528127\",\"FMFID\":\"\",\"FMFNasalBone\":\"-\",\"NTQRID\":\"\",\"NTQRNasalBone\":\"-\",\"MiddleName\":\"\",\"Suffix\":\"MD\",\"Comments\":\"\"},{\"FirstName\":\"\",\"LastName\":\"\",\"NPI\":\"\",\"FMFID\":\"\",\"FMFNasalBone\":\"\",\"NTQRID\":\"\",\"NTQRNasalBone\":\"\",\"MiddleName\":\"\",\"Suffix\":\"\",\"Comments\":\"\"}","ContentEncoding":null,"ContentType":"application/json"}}
I am getting a 200 response.
Here is the response:
{"draw":2,"recordsTotal":24999,"recordsFiltered":24999,"data":{"Content":"{\"FirstName\":\"Sara\",\"LastName\":\"Blake\",\"NPI\":\"1366528127\",\"FMFID\":\"\",\"FMFNasalBone\":\"-\",\"NTQRID\":\"\",\"NTQRNasalBone\":\"-\",\"MiddleName\":\"\",\"Suffix\":\"MD\",\"Comments\":\"\"}
I can't get rid of the backslashes, even with String.Replace. Any ideas?
I'm not familiar with PHP which I'm guessing is what you are using. The problem looks like you are converting
Content
to a JSON string, note the"
between the:
and{
->{"Content":"{\"Fi
. What I think you need to do is convert the value ofContent
to the JSON string and return it in thedata
object, to look more like this:Next you need your row objects to be in an array whether its one row or more. Should look like this:
Needs to look like this doc:
https://datatables.net/manual/data/#Objects
Kevin
Ken.
I am using C# on ASP.net MVC. I am using JsonResult class if you know it.
I formatted my data like above, but it didn't work. I am getting a
this response back
"\"data\":\r\n[\r\n{\"FirstName\":\"IRWIN\",\"LastName\":\"GOLDSTEIN\",\"NPI\":\"1366528127\",\"FMFID\":\"\",\"FMFNasalBone\":\"-\",\"NTQRID\":\"\",\"NTQRNasalBone\":\"-\",\"MiddleName\":\"\",\"Suffix\":\"MD\",\"Comments\":\"\"}
I am trying to use the string.replace to get rid of the backslashes but it doesn't seem to work.
I had a previous version that did work, but that created alot of objects, one for each person. This really slowed things down. Moving everything to an array sped it up, but I can't get datatables to accept the new input.....
You are on the right track. Maybe you can post your code that generates the JSON. It still looks like a standard string not a JSON string.
Kevin
I found another, very slow way to create the JSON. NOT an option, but it gave me this output, which datatables was accepting. I'll use it as my template.
{"draw":2,"recordsTotal":326,"recordsFiltered":326,
"data":
[
{"ClientID":0,"Title":null,"FirstName":"Carrie","MiddleName":null,"LastName":"Snyder","Suffix":null,"ReportDisplayName":null,"FMFID":"46157","FMFExpirationDate":null,"FMFNasalBone":null,"NasalBoneStartDate":null,"NTQRID":"","NTQRExpirationDate":null,"NTQRNasalBone":null,"Comments":"ARDMS 46493 EXP 12/31/13 \u0026 AMER REG OF RADIOLOGIC TECH 293883","AccountCreatedBy":null,"NPI":"","CreatedDate":"\/Date(-62135578800000)\/","CreatedBy":null,"ModifiedDate":"\/Date(-62135578800000)\/","ModifiedBy":null,"Enabled":false,"Visible":false,"LockedDate":null,"LockedBy":null,"FMFUtAD":null,"NTQRUtAD":null,"Affiliations":[]},
Maybe you can post your C# code on Stackoverflow to get the better options.
Kevin
NewtonSoft's JSON.NET is about as close to standard as you get for creating JSON in C# as far as I am aware (other than the built in serialises). But yes, if you need to refine C# code, SO is probably the best place to ask.
Allan
Thanks Allan. I am using JSON.NET and it created the correct string in the correct format. Progress!
I'm getting an Ajax error now, (http://datatables.net/tn/7) so I'm off to solve that.
I am trying to get the results of a query in ASP.NET MVC to appear in the data tables. Here is an example of the JSON it produces, which JSONLint says is valid. I am using a JsonResult class/object to store the data.
"{ "draw":2,"recordsTotal":326,"recordsFiltered":326,"data":[ { "FirstName": "David", "LastName": "Samir", "NPI": "1366528127", "FMFID": "", "FMFIDNasalBone": "-", "NTQRID": "", "NTQRIDNasalBone": "-", "MiddleName": "", "Suffix": "MD", "Comments": "" }, { "FirstName": "Dr Wilson", "LastName": "", "NPI": "", "FMFID": "", "FMFIDNasalBone": "-", "NTQRID": "", "NTQRIDNasalBone": "-", "MiddleName": "", "Suffix": "", "Comments": "" }, { "FirstName": "", "LastName": "", "NPI": "", "FMFID": "", "FMFIDNasalBone": "", "NTQRID": "", "NTQRIDNasalBone": "", "MiddleName": "", "Suffix": "", "Comments": "" }]"
Instead, the page never renders (just spins and spins and spins.)
Maybe you can use the Datatables Debugger to capture the full JSON result:
https://datatables.net/manual/tech-notes/10#DataTables-debugger
Please post the URL provided by the debugger.
Kevin
My code is ufoxec
Go to the debug link click on the Tables tab > Server interaction. Scoll to the bottom and you will see the JSON serializer. Looks like there is a
maxJsonLength
property you may need to set.Kevin
I've set maxJsonLength to 8675309 on JsonResult
I have no idea. Stackoverflow is probably your best bet to find an answer. Did find this but not sure if it is helpful:
https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config
Kevin