How to indicate hasNext from server side processing
How to indicate hasNext from server side processing
Hi! I was able to show my database data without problems. The only issue I'm having is that the datatable has a page control that always shows 1,2,3,4,5...
Right now I have only 15 records so it should show only page 1 and 2.
From server side I'm using a JPA repository so I can know if I have more rows:
@Service("DocumentService")
public class DocumentServiceImpl implements DocumentService {
@Autowired
private DocumentRepository documentRepository;
@Override
public List<Document> getAllDocuments(Pageable pageable) {
Page<Document> page = documentRepository.findAll(pageable);
// page.hasNext() WHAT TO DO WITH THIS VALUE?
return page.getContent();
}
}
Right now the @RestController is doing this:
@RequestMapping(path = "/listdocuments", method = RequestMethod.GET)
public List<Documents> getAllDocuments(HttpServletRequest request) {
return documentService.getAllDocuments(RequestPageable.buildPageableByRequest(request));
}
What should I do to inform the datable the pageCount/hasNext values to the controller?
Thanks!
This question has an accepted answers - jump to answer
Answers
DataTables' server-side processing parameters are documented here, including the information it expects to get in return.
You should only really need to use server-side processing if you are working with tens of thousands of records.
Allan
Sorry.. i'm getting 404 page not found. Right now I have a few records because I'm starting with the app.. but It will grew a lot.
Hi! thanks for the link. I was able to show the correct information like this:
Edited the javascript, added this:
And then changed the response to this(added recordsTotal and recordsFiltered in the response json)