Paging does not work when processing on the server side
Paging does not work when processing on the server side
iraldoad
Posts: 4Questions: 2Answers: 0
My datatable works fine, except for paging, it is disabled.
$('#datatable').dataTable({
'paging': true,
'ordering': true,
'info': true,
'order': [[2, 'desc']],
"columnDefs": [
{"orderable": false, "targets": 6}
],
"processing": true,
"serverSide": true,
"ajax": 'list-load.php',
"deferRender": true
});
public function loadListAction(Request $request)
{
$strSearch = $request->query->get('search');
$start = (int)$request->query->get('0');
$length = (int)$request->query->get('length');
$rep = $this->getDoctrine()->getRepository(Reserva::class);
// Filtered results
$bookings = $rep->findForDatatable($strSearch, $start, $length)->getQuery()->getResult();
// All records
$total = $rep->countAll();
$data = [];
foreach ($bookings as $b) {
$data[] = [
$b->getAd(),
$b->getCl(),
$b->getStart(),
$b->getEnd(),
$b->getEstado(),
$b->getGain(),
'html',
];
}
// Array for response
$res = [
'recordsTotal' => $total,
'recordsFiltered' => count($bookings),
'data' => $data,
];
return new JsonResponse($res);
}
This discussion has been closed.
Answers
Hi @iraldoad ,
It looks like you're always getting page 0 with this line:
You should check the request and see what page the client is asking for,
Cheers,
Colin
Hi @colin now I wrote it this way. The error remains.
This is the response from the controller:
You need to review this doc to understand the parameters sent to the server and the expected response:
https://datatables.net/manual/server-side
Your response is incomplete and the
recordsFiltered
looks to be incorrect. Thedraw
parameter is used as a sequence number. You need to return the samedraw
value that was sent in the request. If this parameter is not correct then Datatables won't show the expected data. Your response doesn't appear to have this parameter but it is needed.Less important is
recordsFiltered
is the number of records filtered when searching, not the number of rows returned. The value you are returning is incorrect but shouldn't stop the page from displaying.Kevin