سؤال

I have jQuery data tables function I get from another question on SO. Here is the function:

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 + ' ';
    }
});

This function is to displaying page/totalpage on pagination. But when I do search on search box, with no record inside the table, the pagination displaying NaN/Nan.

How to keep this pagination still displaying page/totalpage number?

هل كانت مفيدة؟

المحلول

totalRatio = (iTotal/perPage !== iTotal/perPage) ? 0 : iTotal/perPage;
//..
currentRatio = (iStart/perPage !== iStart/perPage) ? 0 : iStart/perPage;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top