Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82109

Problem to bind a Datatable from ASP.NET

$
0
0
Hello,

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

I have this code for js ;
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" }
		]
	});
});

and my Server-Side code is :

[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);

}

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

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

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

the object aData is undefined...

for ( i=0 ; i<aData.length ; i++ )
{
	_fnAddData( oSettings, aData[i] );
}

Do you have any idea to solve this problem? I have been browsing the web for days to find a solution, but nothing... I give up and ask for your help. Thanks in advance.

Viewing all articles
Browse latest Browse all 82109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>