Problem to bind a Datatable from ASP.NET

Problem to bind a Datatable from ASP.NET

FrakerFraker Posts: 3Questions: 0Answers: 0
edited January 2013 in General
Hello,

I'm trying to use DataTable-1.9.4 with an ASP.NET Website.

I have this code for js ;
[code]
var oTable;
$(document).ready(function () {

oTable = $('#content_table').dataTable({
"bPaginate": true,
"sPaginationType": "full_numbers",
"bAutoWidth": true,
"bJQueryUI": false,
"bLengthChange": true,
"sAjaxSource": "ventes_new_datatables.aspx/GetSales",
"fnServerData": function (sSource, aoData, fnCallBack) {
$.ajax({
type: "POST",
url: sSource,
data: aoData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$("#info_div").text(jQuery.parseJSON(data.d));
fnCallBack(jQuery.parseJSON(data.d));
}
});
},
"aoColumns": [
//Assign the data to rows
{"mDataProp": "NOROW", "bVisible": false },
{ "mDataProp": "ID", "bVisible": false },
{ "mDataProp": "NOSERIAL" },
{ "mDataProp": "NOM" },
{ "mDataProp": "LADATE" }
]
});
});
[/code]

and my Server-Side code is :

[code]
[WebMethod]
public static string GetVentes()
{
// FILL A DATATABLE FROM ORACLE DB : dtVentes
......

// COUNT ALL RECORDS : nBVentes
......

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

string test = "{ \"aaData\": " + serializer.Serialize(Outils.GetJson(dtVentes)) + ", \"sEcho\" : 1 , \"iTotalRecords\" : " + nBVentes + ", \"iTotalDisplayRecords\" : " + dtVentes.Rows.Count + " }";

return serializer.Serialize(test);

}
[/code]

in the div "info_div", I get the following JSON content :

[code]
{
"sEcho" : "1" ,
"iTotalRecords" : "238790",
"iTotalDisplayRecords" : "10",
"aaData":
[
{"NOROW":"1","ID":"578056","NOSERIAL":"FCC1209-005980","LADATE":"18/09/2012 14:27:46","NOM":"Caisse 1","TOTALHT":"0,739340"},
{"NOROW":"2","ID":"578036","NOSERIAL":"FCC1209-006797","LADATE":"18/09/2012 14:23:13","NOM":"Caisse 1","TOTALHT":"0,995260"},
{"NOROW":"3","ID":"578023","NOSERIAL":"FCC1209-003932","LADATE":"18/09/2012 14:22:15","NOM":"Caisse 1","TOTALHT":"4,407560"},
{"NOROW":"4","ID":"578022","NOSERIAL":"FCC1209-005979","LADATE":"18/09/2012 14:21:48","NOM":"Caisse 1","TOTALHT":"0,502370"},
{"NOROW":"5","ID":"578021","NOSERIAL":"FCC1209-005978","LADATE":"18/09/2012 14:21:13","NOM":"Caisse 1","TOTALHT":"0,7109"},
{"NOROW":"6","ID":"578020","NOSERIAL":"FCC1209-006796","LADATE":"18/09/2012 14:20:59","NOM":"Caisse 1","TOTALHT":"1,895740"},
{"NOROW":"7","ID":"578019","NOSERIAL":"FCC1209-005548","LADATE":"18/09/2012 14:20:34","NOM":"Caisse 2","TOTALHT":"2,559240"},
{"NOROW":"8","ID":"578018","NOSERIAL":"FCC1209-006795","LADATE":"18/09/2012 14:20:10","NOM":"Caisse 1","TOTALHT":"2,218040"},
{"NOROW":"9","ID":"578017","NOSERIAL":"FCC1209-006794","LADATE":"18/09/2012 14:19:25","NOM":"Caisse 1","TOTALHT":"6,872030"},
{"NOROW":"10","ID":"578016","NOSERIAL":"FCC1209-003931","LADATE":"18/09/2012 14:17:46","NOM":"Caisse 1","TOTALHT":"5,308060"}
]
}
[/code]

but when I load the page, I get a js error from jquery.dataTables.js in function _fnInitialise ( oSettings ).

the object aData is undefined...

[code]
for ( i=0 ; i

Replies

  • FrakerFraker Posts: 3Questions: 0Answers: 0
    The server-side function is called GetSales() and not GetVentes(), I made a mistake
  • FrakerFraker Posts: 3Questions: 0Answers: 0
    Still get the error, can someone help me please ?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > "iTotalDisplayRecords" : "10"

    Looks dodgy. From the documentation ( http://datatables.net/usage/server-side ):

    > Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)

    Other than that - it looks like it probably should be. Please link to a test case so we can see what is happening.

    Allan
This discussion has been closed.