我的页面上有一个数据表,该数据表按预期工作,除了单击上一个或下一个导航按钮时更新页码之外。
每次单击下一个按钮都会使页面从0-> 1-> 2-> 3 ...递增,但是按一下prev按钮不会将其带回到第0页,而是带回到1。实际上,第0页信息是在ui上显示,但page.info()。page将页码显示为1。
请帮助,为什么上一个按钮没有将页码更新为0,而是UI在第0页上显示信息。
swal({
title: "Message Sent",
icon: '{{ asset('assets/images/mpesa.png')}}',
imageWidth: 30,
imageHeight: 30,
imageAlt: 'Mpesa Icon',
text: "Please Check your Phone for a payment dialogue" + '<i class="fa fa-spinner fa-spin"></i>',
closeOnClickOutside: false,
buttons:false
});
function initializeInProgressShipmentsTable(pageSize) {
var tableId = "#in-progress-shipments-table";
var dataTable = $(tableId).DataTable({
"lengthChange": false,
"pageLength": pageSize,
"processing": true,
"pagingType": "simple",
"retrieve": true,
"order": [],
"columns": [
{"data": "link"},
{"data": "link2"},
{"data": "link3"},
{"data": "rc"},
{"data": "link4"},
{"data": "oc"},
{"data": "st"},
{"data": "link5"}
],
"drawCallback": function (settings) {
var api = this.api();
addClickEventListenerOnNextButton(tableId);
enableNextButton(api, pageSize, tableId);
}
});
return dataTable;
}
/**
* Function that adds a listener to click event on next button.
* It will only loads data from the server if last page is displayed and next button is not disabled
* @param tableId
*/
function addClickEventListenerOnNextButton(tableId) {
$(tableId + "_next").click(function () {
var dataTable = $(tableId).DataTable();
var pageInfo = dataTable.page.info();
var isNextButtonEnabled = $(tableId + '_next.paginate_button.next.disabled').length > 0 ? false : true;
if (isNextButtonEnabled && ((pageInfo.page + 1) >= pageInfo.pages)) {
$("#loader_wrapper").show();
$.ajax({
type: "GET",
url: getURL(tableId, getPageSize(tableId)),
async: false,
success: function (response) {
if (response.responseCode == "SUCCESS") {
loadResultAndRedrawTheTable(tableId, response);
increaseCallTimes(tableId);
$("#loader_wrapper").hide();
$('.load_failed').hide();
} else {
showErrorMessage("Loading new results failed, Error : " + response.message);
}
},
error: function () {
showErrorMessage("Loading new results failed, Please try after sometime.");
}
});
}
});
}