How to display Empty row if Ajax response is empty

How to display Empty row if Ajax response is empty

sheraz4prosheraz4pro Posts: 5Questions: 0Answers: 0
edited March 2013 in DataTables 1.9
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]

Replies

  • sheraz4prosheraz4pro Posts: 5Questions: 0Answers: 0
    can somebody help me please?????
  • sheraz4prosheraz4pro Posts: 5Questions: 0Answers: 0
    how to display empty row when server response is empty????
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Use http://datatables.net/ref#sEmptyTable - which is what DataTables shows when you ask it to display an empty table.
  • sheraz4prosheraz4pro Posts: 5Questions: 0Answers: 0
    edited March 2013
    I have used sEmptyTable, I think the problem is JSON. When there is no record then the JSON returned by AJAX call is either wrongly formatted or do not contains required information properly. What i am returning in case of "No records" is

    [code]

    {
    "sEcho": 0,
    "iTotalRecords": "0",
    "iTotalDisplayRecords": "0",
    "aaData": [
    ]
    }


    [/code]

    is there anything missing or need to be corrected? please guide me.
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    sEcho should never be 0. See: http://datatables.net/usage/server-side
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Oh - and iTotalRecords etc should be integers. Again, see the documentation.
  • sheraz4prosheraz4pro Posts: 5Questions: 0Answers: 0
    Thanks allan, It is working now, I love u man :)
This discussion has been closed.