How can you setup pagination on Datatables with Elasticsearch? I've already populated the Datatables with Elasticsearch result but it's not rendering pagination properly.
clicking on the numbered links will yield same data
Here's my JS code:
var searchResultTable = $('#search-results').DataTable({
"processing": true,
"serverSide": true,
"ajax": "elasticsearch/",
"dom": "<'row'<'col-sm-6'l>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-5'i><'col-sm-7'p>>",
});
Here's my views.py (An excerpt; I'm using Django):
def elasticsearch_result_json(request):
search_query = request.GET.get('search[value]', None)
results = search_service.get_remittances_json(search_query)
return JsonResponse(
{
'data': results
}
)
The pagination is now working correctly but the data the table is showing
is the same in all pages.
Here's my updated views.py:
def elasticsearch_result_json(request):
search_query = request.GET.get('search[value]', None)
results = search_service.get_remittances_json(search_query)
total_records = search_service.get_total_count()
return JsonResponse({
'draw': request.GET.get('draw', 0),
'recordsTotal': total_records,
'recordsFiltered': len(results),
'data': results,
})

request, you will see the parameters relating to paging, sorting etc. You need to use these in your query to handle paginination.. See datatables.net/manual/server-sidestartand 'length' parameters in your query."displayStart": 10and"pageLength": 10but the problem persists.startandlengthparameters - in the same way as you do forsearchanddraw- and use them in your SQL query to page the data. Without this, you're just returning the same data on every time.