Dataable in asp.net webforms
Dataable in asp.net webforms
Hi Guys,
I have done implementation for datatables in php successfully,I was trying the same in asp and I am an experiencing an error and has dragged me quiet abit.see below my json output:
JS
var table = $("#tblFindPatient").dataTable({
bAutoWidth: false,
bDestroy: true,
bJQuieryUI: true,
"aaSorting": [],
bProcessing: true,
bServerSide: true,/*
"aocolumns": [
{ "mData": "EnrollmentNumber"},
{ "mData": "PatientIndex" },
{ "mData": "FirstName" },
{ "mData": "MiddleName" },
{ "mData": "LastName" },
{ "mData": "DateOfBirth" },
{ "mData": "Sex" },
{ "mData": "RegistrationDate" },
{ "mData": "PatientStatus" }
],*/
"aoColumns": [
{"sName": "EnrollmentNumber", "sTitle": "Enrollment Number" },
{ "sName": "PatientIndex", "sTitle": "Patient Index" },
{ "sName": "FirstName", "sTitle": "First Name" },
{ "sName": "MiddleName", "sTitle": "Middle Name" },
{ "sName": "LastName", "sTitle": "Last Name" },
{ "sName": "DateOfBirth", "sTitle": "Date of Birth" },
{ "sName": "Sex", "sTitle": "Gender" },
{ "sName": "RegistrationDate", "sTitle": "Registration Date" },
{ "sName": "PatientStatus", "sTitle": "Patient Status" }
//this name should exist in your JSON response
//"render": function ( data, type, full, meta ) {
// return '<span class="label label-danger">'+data+'</span>';
//}
],
"sAjaxSource": "../WebService/PatientLookupService.asmx/FindPatient",
"fnServerData":function(sSource, aoData, fnCallback, oSettings) {
aoData.push({ "name": "patientId", "value": ""+$("#<%=PatientNumber.ClientID%>").val()+"" });
aoData.push({ "name": "firstName", "value": ""+$("#<%=FirstName.ClientID%>").val()+"" });
aoData.push({ "name": "middleName", "value": ""+$("#<%=MiddleName.ClientID%>").val()+"" });
aoData.push({ "name": "lastName", "value": ""+$("#<%=LastName.ClientID%>").val()+"" });
aoData.push({ "name": "DateOfBirth", "value": "" + moment($("#SearchDoB").datepicker('getDate')).format('DD-MMM-YYYY') + "" });
aoData.push({ "name": "gender", "value": ""+$("#<%=Sex.ClientID%>").find(":selected").text()+"" });
aoData.push({ "name": "facility", "value": ""+$("#<%=Facility.ClientID%>").find(":selected").text()+"" });
aoData.push({ "name": "registrationDate", "value": ""+moment($("#RegDate").datepicker('getDate')).format('DD-MMM-YYYY') +"" });
oSettings.jqXHR = $.ajax({
"dataType": 'json',
"type": 'POST',
"contentType": 'application/json; charset=utf-8',
"url": sSource,
"data": JSON.stringify({ dataPayLoad: aoData }),
"success": function (response) { var json = response.d;
fnCallback(json) },
"error":function (xhr,errorType,exception) {
var jsonError = jQuery.parseJSON(xhr.responseText);
toastr.error("" + xhr.status + "" + jsonError.Message+" "+jsonError.StackTrace+" "+jsonError.ExceptionType, "Patient Finder Method");
return false;
}
});
},
sAjaxDataProp: "",
"responsive":true,
"bPaginate": true,
"lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]]
});
{"d":"{\"draw\":1,\"recordsTotal\":1,\"recordsFiltered\":1,\"aaData\":[[\"2\",\"1065-2017\",\"MvhZninO7Fs=\",\"MvhZninO7Fs=\",\"28by3aG1iNw=\",\"2/2/2017\",\"62\",\"2/7/2017\",\"False\"]]}"}
Error
Datatables warning:table id=tbFindPatient - Request unknown parameter '1' for row '0',column 1.
any help ??
Answers
The problem is the returns JSON. It is being wrapped in a
d
parameter with a string. I've no idea why Microsoft though that might be a good idea, but you need to modify your server-side to return just the JSON that is required.Exactly how you do that I don't know. But if you found out, could you let me know as this comes up a lot!
Allan