I am using jQuery DataTable to display a huge amount of data in a table. I get an Ajax request data page as follows:
var pageNo = 1; $('#propertyTable').dataTable( { "processing": true, "serverSide": true, "ajax": "${contextPath}/admin/getNextPageData/"+pageNo+"/"+10, "columns": [ { "data": "propertyId" }, { "data": "propertyname" }, { "data": "propertyType" }, { "data": "hotProperties" }, { "data": "address" }, { "data": "state" }, { "data": "beds" }, { "data": "city" }, { "data": "zipCode" } ], "fnDrawCallback": function () { pageNo = this.fnPagingInfo().iPage+1; alert(pageNo);
and here is the spring controller:
@RequestMapping(value="/getNextPageData/{pageNo}/{propertyPerPage}") public @ResponseBody PropertyDatatableDto getNextPageData(@PathVariable Integer pageNo, @PathVariable Integer propertyPerPage) { System.out.println("called"); System.out.println(pageNo); // this always prints 1, what i need is current pageNo here PropertyDatatableDto datatableDto = new PropertyDatatableDto(); //datatableDto.setDraw(1); datatableDto.setRecordsTotal(100); datatableDto.setRecordsFiltered(100); datatableDto.setData(adminService.getAllPropertyList()); return datatableDto; }
The problem is that when I change the page in the table, it warns correctly pageNo on the page (in JavaScript), but in the spring controller I always get the initial value assigned to the variable pageNo , and not the current page number.
How to pass dynamic pageNo to spring controller? Any help is appreciated.
Edit:
I updated JavaScript as follows:
var oSettings = $('#propertyTable').dataTable().fnSettings(); var currentPageIndex = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; $('#propertyTable').dataTable({ "processing": true, "serverSide": true, "ajax": "${contextPath}/admin/getNextPageData/"+currentPageIndex+"/"+10, "columns": [ { "data": "propertyId" }, { "data": "propertyname" }, { "data": "propertyType" }, { "data": "hotProperties" }, { "data": "address" }, { "data": "state" }, { "data": "beds" }, { "data": "city" }, { "data": "zipCode" } ] });
But this gives me an error:
Warning DataTables: table id = propertyTable - Unable to reinitialize the DataTable.