Page X of Y pagination
Page X of Y pagination
stormblade
Posts: 10Questions: 0Answers: 0
Hey all,
I was looking for a way to customize the pagination to be Page x of y instead of the Showing x to y of z entries. And just the four button navigation. Looking over the documentation it looks like I need to create a custom pagination control and I saw the examples. I couldn't really tell which would be suitable for my needs as a base because I couldn't get the live example to work properly. Every one seems to render the same.
So can anyone help me? Or point me to where someone has already done this? I can't imagine no one has needed it to read this way.
Thanks in advance.
I was looking for a way to customize the pagination to be Page x of y instead of the Showing x to y of z entries. And just the four button navigation. Looking over the documentation it looks like I need to create a custom pagination control and I saw the examples. I couldn't really tell which would be suitable for my needs as a base because I couldn't get the live example to work properly. Every one seems to render the same.
So can anyone help me? Or point me to where someone has already done this? I can't imagine no one has needed it to read this way.
Thanks in advance.
This discussion has been closed.
Replies
Four button pagination plug-in is available here: http://datatables.net/plug-ins/pagination#four_button
Allan
Thanks again.
Allan
When I do it like the example it tells me that fnInfo is not a function. I try fnPagingInfo and get the same so I did a console.log(this) to see what I was working with and I do not see that function anywhere.
I've just committed a fix for this into the 1.9 development version (shortly to be released as 1.9.beta.1). You can get the latest version from here: https://github.com/DataTables/DataTables/blob/1_9_DEV/media/js/jquery.dataTables.js
With that, this is what is needed to get the table information to look like what you want:
[code]
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
}
$(document).ready(function() {
$('#example').dataTable( {
"fnInfoCallback": function ( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
var o = this.fnPagingInfo();
return "Page "+(o.iPage+1)+" of "+o.iTotalPages;
}
} );
} );
[/code]
Regards,
Allan
regarding fnInfoCallBack, is there any way to explicitly call this function? i.e. adding a new row and update the "x elements found" message.
Great work by the way!
Allan