I need to load some data into a datatables table using server side processing.
I need to return a custom JSON object to the aaData property of the datatables object, to do some custom formatting. I can't simply return an array of strings.
I'm a newbie in datatables and javascript / ajax so please bare with me.
This is my controller action where I return an array (this is what I need to update):
var result = from u in filteredResults
select new string[] {Convert.ToString(u.userId), u.userName, u.roleId.ToString(), u.type, u.isActive.ToString(), u.firstName, u.lastName,
u.email, u.phone, u.Postcode, u.Street, u.Street, u.company, u.jobId.ToString(), u.job, u.country, u.countryName, u.City, u.LoginsNum.ToString(),
u.LastLogin.ToString()};
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = result.Count(),
iTotalDisplayRecords = result.Count(),
aaData = result ** NOT OK; must be updated **
}, JsonRequestBehavior.AllowGet);
The resulting object must be in this form:
[
{ "prop1": "val1",
"prop2": "val2",
......
"propn": "valn"
},
.................
{ "prop1": "val1",
"prop2": "val2",
......
"propn": "valn"
},
]