I am using jQuery DataTable to display huge amount of data in a table. I am getting data page wise on Ajax request like this:
var pageNo = 1;
$(\'#propertyTa
"Untested" Edit: Added "retrieve": true in options to retrieve the table instance (v1.10), checked if table exists. Changed fnSettings to setting() for datatable v1.10.
You can try to read from the datatable settings and then from settings read _iDisplayStart and _iDisplayLength , then calculate current page index as follows:
var currentPageIndex = 1;
//Is datatable already initialized?
if ( $.fn.DataTable.isDataTable( '#propertyTable' ) ) {
//Get the current settings and calculate current page index
var oSettings = $('#propertyTable').dataTable({"retrieve": true}).settings();
currentPageIndex = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
}
then in ajax call pass currentPageIndex:
"ajax": "${contextPath}/admin/getNextPageData/"+currentPageIndex +"/"+10,
DataTables already sends parameters start
and length
in the request that you can use to calculate page number, see Server-side processing.
If you still need to have the URL structure with the page number, you can use the code below:
"ajax": {
"data": function(){
var info = $('#propertyTable').DataTable().page.info();
$('#propertyTable').DataTable().ajax.url(
"${contextPath}/admin/getNextPageData/"+(info.page + 1)+"/"+10
);
}
},