0

in web.config of web service that returns more than 40,000 records I have set maxlength for json serialization

<system.web.extensions>
   <scripting>
      <webServices>
         <jsonSerialization maxJsonLength="50000000"/>
      </webServices>
   </scripting>
</system.web.extensions>
function BindInfoDataTableServerSide() 
{
    var oTable = $('#example').dataTable({
        "sScrollY": "250px",
        'bPaginate': true,
        "bProcessing": true,
        "bFilter": false,
        "bServerSide": true,
        //"aoColumns": [null, null, { "bSortable": false }, { "bSortable": false}, null, null, null, null],
       /* "aoColumns": [
                { "sTitle": "ScreenId" },
                { "sTitle": "RunId" },
                { "sTitle": "RecordType" },
                { "sTitle": "TrackerKey" },
                { "sTitle": "SeqNo" },
                { "sTitle": "TRSeqNo" },
                { "sTitle": "TestParam" },
                { "sTitle": "ParamValue" },
            ]
        ,*/
        "sAjaxSource": "../SocWebService.asmx/LoadMidasData",
        "sAjaxDataProp": "aaData",
        "fnServerData": function (sSource, aoData, fnCallback) { GrabData(sSource, aoData, fnCallback); }
    });

}

function GrabData(sSource, aoData, fnCallback) {

    $.ajax({
        type: "POST",
        url: sSource,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: "",
        success: function (result) {
            var  myObject = JSON.parse(result.d);

            fnCallback(myObject);
            //fnCallback(result.d);
        },
        error: function (errMsg) {
            alert(errMsg);
        }
    });

}

But when records go to 50,000 then I run into following Error

during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. Jquery datatables website claim they can display 1 million records. Am I missing something ?

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
  • Try set `maxJsonLength="0"` (0 for unlimited) or `2147483644`. See this question / answers / links within -> http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config – davidkonrad Nov 16 '14 at 13:18

1 Answers1

0

The main idea of using server side processing with DataTables is so that the server only returns the rows currently needed for display in the browser (as the user pages around, and sorts etc.) - so while there might in fact be 1 million records, only a small section of those should returned by the web service call, so the ajax limit should not be exceeded.

That way the client side remains nice and fast, with the heavy work getting done on the server (or perhaps in the database depending on how you have your data generated).

  • I do not find a good example on how to return rows required for display. As you see in code below I am returning all the data each time I make server side call. This is taxing. Can you suggest ways to do pagination of data on server and send that data. var wrapper = new FooWrapper() { sEcho = 0, iTotalRecords = dt.Rows.Count, iTotalDisplayRecords = dt.Rows.Count, aaData = jsDT.aaData, aoColumns = jsDT.aoColumns }; return wrapper; – user3768889 Nov 19 '14 at 22:21