当找不到jQuery数据表的结果时显示NaN / NaN

时间:2014-02-08 05:39:16

标签: jquery jquery-datatables

我有从j上的另一个问题得到的jQuery数据表函数。这是功能:

var oTable = $('#test').dataTable( {
    "aoColumnDefs": [
        { "bSortable": false, "aTargets": [ 0 ] }
    ],
    "aaSorting": [[1, 'asc']],
    "iDisplayLength": 1,
    "bInfo": true,
    "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
       perPage = iEnd - iStart + 1;
       totalRatio = iTotal/perPage;
       intTotalRatio = parseInt(totalRatio, 10);
       totalPages = totalRatio > intTotalRatio ? intTotalRatio + 1 : intTotalRatio;
       currentRatio = iStart/perPage;
       intCurrentRatio = parseInt(currentRatio, 10);
       currentPage = currentRatio > intCurrentRatio ? intCurrentRatio + 1 : intCurrentRatio;
       return ' ' + currentPage + ' / ' + totalPages + ' ';
    }
});

此功能用于在分页上显示页面/总页数。但是当我在搜索框上搜索时,表中没有记录,分页显示NaN / Nan。

如何保持此分页仍显示页面/总页数?

1 个答案:

答案 0 :(得分:0)

totalRatio = (iTotal/perPage !== iTotal/perPage) ? 0 : iTotal/perPage;
//..
currentRatio = (iStart/perPage !== iStart/perPage) ? 0 : iStart/perPage;