I am trying to load data from ajax call from the pagination on the html page but it is somehow not working.. not able to understand the problem
I have checked this link but ajax call is not working in my code i need to fetch the list of Company Registration and populate in the datatable with the implementation of pagination and while controlling the loading time of the page through pagination.(like the records are 5000 and it loads all together i need to fix server side pagination from ajax)
Passing pageable (spring data) in post request
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js">
<script type="text/javascript">
$(document).ready(function(){
$('#shortstorage').DataTable({
"pageLength": 5,
"processing": true
"serverSide": true
"ajax": {
"url": "/getcompany",
"type": "GET"
}
}
} );
});
</script>
The call is make to the getcompanyy method in the controller
@RequestMapping(value = "/getcompanyy", method = RequestMethod.GET)
public String getCompanyy(Model model,HttpServletRequest request, @PageableDefault(value=10, page=0) Pageable pageable) {
pageable = new PageRequest(pageable.getPageNumber(), pageSize, sort);
Page<CompanyRegistration> compregPag = companyregister.findAll(pageable);
List<CompanyRegistration> compreg = compregPag.getContent();
model.addAttribute("compreg",compreg);
return "admin/company";
Error
The code is loading all rows in data table without the pagination applied
2
Answers
You actually should return JSONObject,
take a look at this RestController, I think this is what you need:
https://github.com/solutionman/BaseProject/blob/master/src/main/java/com/project/base/controller/BaseProjectRestController.java
});
pagenumber and pagerows youll get from start and length (from data) :
int start = Integer.parseInt(data.get(“start”));
int length = Integer.parseInt(data.get(“length”));
and according to them select objects for rows from database, arrayList here just for example.
compregPag
has content that is needed along with metadata. Use that as a model attribute.