Can not populate JQuery DataTable with my json data
Can not populate JQuery DataTable with my json data
sonofspm
Posts: 4Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
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