How to get the number of pages in DataTables

2019-05-16 21:17发布

I am working with DataTables and I need to know the current number of pages that a table holds (this certainly depends on the number of rows per page and the total number of rows and may change by user-action). Does anybody know how to access this value?

1条回答
孤傲高冷的网名
2楼-- · 2019-05-16 21:22

I believe iTotalPages is what you're after: http://datatables.net/plug-ins/api#fnPagingInfo

$.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings){
    return {
        "iTotalPages": oSettings._iDisplayLength === -1 ?
            0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
    };
};    

$('#example').dataTable({
    "fnDrawCallback": function(){
        alert('There are ' + this.fnPagingInfo().iTotalPages + ' in this table.');
    }
});
查看更多
登录 后发表回答