sAjaxSource with Objected Json

sAjaxSource with Objected Json

xujihui1985xujihui1985 Posts: 1Questions: 0Answers: 0
edited April 2011 in General
Hi Allen,

In the previous edition of Datatables, the objected Json is not supported for sAjaxSource datasouce, is this problem fixed in the new edition?

eg:
[code] IList l = new MYERPBLL.CustomerService().GetAllCustomerArray();
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = 50,
iTotalDisplayRecords = 50,
aaData = l
},JsonRequestBehavior.AllowGet);
[/code]
[code] $(function () {
$("#example").dataTable({
//"bServerSide": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"sAjaxSource": "/Home/AjaxHandler",
"bFilter" : false
// "aoColumns" : [
// { " sName " : " ID "},
// { " sName " : " COMPANY_NAME " },
// { " sName " : " ADDRESS " },
// { " sName " : " TOWN " }
// ]
});
});
[/code]

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    This was an intentional change. Basically DataTables requires the JSON information to be displayed in the table to come back as a string - otherwise, how to you represent a boolean or object in the table? I'm looking at relaxing this constraint in DataTables 1.8 - so keep an eye out for that :-). Also there is a plug-in available which will convert an array of objects into the array of arrays that DataTables needed, which might help you: http://datatables.net/plug-ins/server-data-formats#json_object .

    Allan
This discussion has been closed.