How to display Empty row if Ajax response is empty
How to display Empty row if Ajax response is empty
sheraz4pro
Posts: 5Questions: 0Answers: 0
Hi, i am new to Datagrid. I am working on a CV management system in which i am using datatable Plugin to show all applicants via AJAX. I have a filter form which will will filter the data via different criteria using AJAX.
everything is working fine. But the issue is When server sends no/empty data, then i don't understand how to display an empty rows of table and display an error message i.e. "No records found."
Here is the Code
[code]
//this function will be called in document.ready() with parameter as 0;
function display_applicant_list(req_type){
if(req_type=='0')
rander_datatable("");
else{
//else condition will run when a filter is applied.
//destroying and reinitializing
$("#applicants_list").dataTable().fnDestroy();
var params = "params";
//randering datatable
rander_datatable(params);
//hiding the filter div
$("#filter_div").hide();
}
}
function rander_datatable(params){
$('#applicants_list').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sPaginationType": "bootstrap",
"sDom": '<"H"Cfr>t<"F"ip>',
"oColVis": {
"activate": "mouseover",
"aiExclude": [ 10 ],
"sAlign": "left"
},
"bFilter": false,
"sAjaxSource": "script.php",
"aoColumns": [
{"bSortable": true }, // attachments
{"bSortable": true }, //Subject Line
{"bSortable": true }, // Date Sent
{"bSortable": true }, // File Name
{"bSortable": false },
{"bSortable": false },
{"bSortable": true },
{"bSortable": true },
{"bSortable": true },
{"bSortable": false }
],
"aaSorting": [[0, 'desc']]
} );
}
[/code]
everything is working fine. But the issue is When server sends no/empty data, then i don't understand how to display an empty rows of table and display an error message i.e. "No records found."
Here is the Code
[code]
//this function will be called in document.ready() with parameter as 0;
function display_applicant_list(req_type){
if(req_type=='0')
rander_datatable("");
else{
//else condition will run when a filter is applied.
//destroying and reinitializing
$("#applicants_list").dataTable().fnDestroy();
var params = "params";
//randering datatable
rander_datatable(params);
//hiding the filter div
$("#filter_div").hide();
}
}
function rander_datatable(params){
$('#applicants_list').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sPaginationType": "bootstrap",
"sDom": '<"H"Cfr>t<"F"ip>',
"oColVis": {
"activate": "mouseover",
"aiExclude": [ 10 ],
"sAlign": "left"
},
"bFilter": false,
"sAjaxSource": "script.php",
"aoColumns": [
{"bSortable": true }, // attachments
{"bSortable": true }, //Subject Line
{"bSortable": true }, // Date Sent
{"bSortable": true }, // File Name
{"bSortable": false },
{"bSortable": false },
{"bSortable": true },
{"bSortable": true },
{"bSortable": true },
{"bSortable": false }
],
"aaSorting": [[0, 'desc']]
} );
}
[/code]
This discussion has been closed.
Replies
[code]
{
"sEcho": 0,
"iTotalRecords": "0",
"iTotalDisplayRecords": "0",
"aaData": [
]
}
[/code]
is there anything missing or need to be corrected? please guide me.