问题
I want to make a hidden row visible when the last page of the datatable is clicked.How can I do this? I could not find the method to get the current page number and the last page number of Jquery Datatable pagination.
This is what I want to do,but I dont have any idea abt how to get current page and last page.
$( "#paginate_button" ).click(function() {
if(.......){ //if clicked page number= last page
$( "#hidden_row" ).show();
else
$( "#hidden_row" ).hide();
});
回答1:
First, implement the wellknown [fnPagingInfo][1] "plugin". Eg add the following to your 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 )
};
}
Then, apply the if condition in fnDrawCallback :
"fnDrawCallback": function () {
var currentPage= this.fnPagingInfo().iPage;
if ((+currentPage + +1) == this.fnPagingInfo().iTotalPages) {
$("#target_id").show();
}else
$("#target_id").hide();
}
});
回答2:
I had a similar issue and that worked for me too. But, I had to put this way (the script must be loaded before the datatable):
$.extend( true, $.fn.dataTable.defaults, {
"fnDrawCallback": function () {
var currentPage= this.fnPagingInfo().iPage;
if ((+currentPage + +1) == this.fnPagingInfo().iTotalPages) {
$("#target_id").show();
}else{
$("#target_id").hide();
}
}
});
});
*I would put it as a comment to the other answer but I don't have enought reputation.
来源:https://stackoverflow.com/questions/21045248/show-a-row-on-the-last-page-of-a-paginated-jquery-datatable