Can not populate JQuery DataTable with my json data

Can not populate JQuery DataTable with my json data

sonofspmsonofspm Posts: 4Questions: 0Answers: 0
edited March 2013 in DataTables 1.9
I'm stuck completely while accessing the data from asp.net web service to .aspx page. I used the Newtonsoft.Json.JsonConvert.SerializeObject(qry, Formatting.Indented) for creating a JSON string.

This library provides a genuine and valid JSON string like following:
[ { "DepartmentId": 0, "Department": "CIVIL ENGG.", "DepartmentShortName": "CIVIL" },
{ "DepartmentId": 10, "Department": "COMPUTER SCIENCE ENGINEERING", "DepartmentShortName": "C.S.E." },
{ "DepartmentId": 21, "Department": "ELECTRICAL & ELECTRONICS ENGG.", "DepartmentShortName": "E.N." },
{ "DepartmentId": 31, "Department": "ELECTRONICS & COMMUNICATION ENGG.", "DepartmentShortName": "E.C.E" } ]

The code snippet to populate the datatable is:
$(document).ready(function() {
$.ajax({
type: "POST",
url: webServiceURL,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(json) {
$('#grid').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": webServiceURL,
"fnServerData": fnDataTablesPipeline
});
}
});
});
for complete set of code, I referred the http://www.datatables.net/examples/server_side/pipeline.html link and indeed tried many other options but no luck.

I suspect that it can be occurred because of 'sEcho', 'iDisplayStart' and 'iDisplayLength' are missing from json but when I used my json string within aspx page and passed to 'aaData', it works fine.

I'm lost and not finding any solution since last three days. I believe some help will come out here..

Thanks in advance

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    1. That JSON is not suitable for server-side processing as it doesn't implement the server-side processing protocol: http://datatables.net/usage/server-side

    2. Use sAjaxDataProp set to an empty string to read the data from the plain source array.

    3. Use mData to tell DataTables which property to use for each table: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
This discussion has been closed.