The Most basic Question of them All: Row 0 Column 0 error.

The Most basic Question of them All: Row 0 Column 0 error.

jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

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

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    I tried to use this as an example:
    https://datatables.net/examples/data_sources/ajax.html

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    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

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    Yup! Exactly what Kevin says.

    If you do want to use columns.data, then you need to return an array of objects in data, not an array of arrays (since data: 'FirstName' is meaningless in an array).

    Allan

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0
    edited December 2017

    Thanks for your reply.

    Here's what I've tried:
    This is one record in the database. I have tried to totally eliminate arrays.

    {"FirstName":"Stacey","LastName":"Smith","NPI":"1366528127","FMFID":"","FMFNasalBone":"-","NTQRID":"","NTQRNasalBone":"-","MiddleName":"","Suffix":"MD","Comments":""}
    
      $('#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,
            "deferRender":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",
                    "dataSrc": "data"
                },
                
            "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 }
            ]
        });
    

    And my Error:
    DataTables warning: table id=TableId - Ajax error. For more information about this error, please see http://datatables.net/tn/7

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    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

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited December 2017

    Did you follow the troubleshooting steps at the link provided in the error?

    The link starts with:

    a general error can be triggered if the server responds with anything other than a valid HTTP 2xx response

    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 calleddata. 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

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    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>

    <body bgcolor="white">
    
            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
    
            <h2> <i>Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.</i> </h2></span>
    
            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
    
            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
            <br><br>
    
            <b> Exception Details: </b>System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.<br><br>
    
            <b>Source Error:</b> <br><br>
    
            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>
    

    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>

                  </td>
               </tr>
            </table>
    
            <br>
    
            <b>Stack Trace:</b> <br><br>
    
            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>
    

    [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(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +52 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +173 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
    System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
    System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22
    System.Web.Mvc.Async.WrappedAsyncResultBase1.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.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
    System.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>

                  </td>
               </tr>
            </table>
    
            <br>
    
            <hr width=100% size=1 color=silver>
    
            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2114.0
    
            </font>
    
    </body>
    

    </html>

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    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"}}

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    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?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    "data":{"Content":"{\"FirstName\":\"Sara\",\"LastName\":\"Blake\",....

    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 of Content to the JSON string and return it in the data object, to look more like this:

    "data":{"FirstName":"Sara","LastName":"Blake",....

    Next you need your row objects to be in an array whether its one row or more. Should look like this:

    "data":
    [
    {"FirstName":"Sara","LastName":"Blake",....,"Comments":""}  <followed by the remaining rows>
    ]
    

    Needs to look like this doc:
    https://datatables.net/manual/data/#Objects

    Kevin

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    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.....

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    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

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    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":[]},

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    very slow way to create the JSON. NOT an option

    Maybe you can post your C# code on Stackoverflow to get the better options.

    Kevin

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    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

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    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.

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0
    edited December 2017

    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.)

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    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

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0

    My code is ufoxec

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    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

  • jon.steiner@gmail.comjon.steiner@gmail.com Posts: 15Questions: 2Answers: 0
    edited December 2017

    I've set maxJsonLength to 8675309 on JsonResult

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    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

This discussion has been closed.