我在我的项目中使用了Datatable 1.9.2。 我通过AJAX显示申请人名单。 还有一个过滤器表单,用于过滤数据。 一切工作正常,但问题是,如果我筛选记录和数据库没有返回数据然后datatable在POPUP中生成一个错误。 有人可以指导我如何处理与数据表空ajax响应,如何处理空数据集。 以下是我正在使用的代码
$('#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']] } );i am using Datatable 1.9.2 in my project. I am display a list of applicants in it via AJAX. There is also a filter form which is used to filter data. Everything is working fine, but the problem is that if i filter records and no data is returned by DB then datatable generates an error in POPUP. Can someone guide me how to handle empty ajax response with datatable, how to handle empty dataset. Below is the code which i am using
$('#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']] } );最满意答案
当过滤器返回记录为空时,只返回来自server / ajax响应的以下数据,它将显示空记录消息。
echo '{ "sEcho": 1, "iTotalRecords": "0", "iTotalDisplayRecords": "0", "aaData": [] }';Just return following data from server/ajax response when filter return record is empty it will display empty record message.
echo '{ "sEcho": 1, "iTotalRecords": "0", "iTotalDisplayRecords": "0", "aaData": [] }';更多推荐
发布评论