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