Serverside: pagination not working
Serverside: pagination not working
Hi all.
My DataTable shows up with 10 records.
below table:
Showing 1 to 10 of 10 entries (filtered from 14,837 total entries)
Previus and Next paginationbuttons are showd, but also just only page 1 between them and no reaction on pshing these buttons.
Ajax part in PHP:
// count total rows in log for this user
$sql = "SELECT COUNT(*) as totalrows FROM logboek WHERE speler = :playerID";
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':playerID', $_SESSION['playerID'],PDO::PARAM_INT);
$stmt->execute();
$aData = $stmt->fetchAll();
$totalRows = $aData[0]['totalrows'];
$sql = "SELECT datum, actie, gameID, opID, opNick, beschrijving
FROM logboek
WHERE speler = :playerID
LIMIT :offset,:limit";
try {
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':playerID', $_SESSION['playerID'],PDO::PARAM_INT);
$stmt->bindValue(':offset', (int) $_GET['start'], PDO::PARAM_INT);
$stmt->bindValue(':limit', (int) $_GET['length'], PDO::PARAM_INT);
$stmt->execute();
$aData = $stmt->fetchAll();
}
catch (PDOException $e) {
echo 'failed: ' . $e->getMessage();
// your error handling (log?) here
exit;
}
$aReturn = array();
$aReturn['draw'] = (int)$_GET['draw'];
$aReturn['recordsTotal'] = $totalRows;
$aReturn['recordsFiltered'] = count($aData);
$aReturn['data'] = array();
foreach($aData as $key => $aRows)
{
$aArray = array();
$aArray[] = $aRows['datum'];
$aArray[] = $aRows['actie'];
$aArray[] = $aRows['gameID'];
$aArray[] = $aRows['opNick'];
$aArray[] = $aRows['beschrijving'];
$aReturn['data'][] = $aArray;
}
//ucms_print_rn($aReturn);
echo json_encode($aReturn);
Response according Firebug:
{"draw":1,"recordsTotal":"14837","recordsFiltered":10,"data": data here etc.
I was expecting that paging is based upon recordsTotal, divided through amount of rows per page and after asking another page, i get a new dataset based upon new offset/limit.
What am i doing wrong here?
This question has an accepted answers - jump to answer
Answers
recordsFiltered should be the same as your recordsTotal if you have not filtered anything. recordsTotal = total records regardless of what has been searched for. recordsFiltered = total records after applying the filter (search).
It looks like your $aData count will always be however many you display at a time or less, which is why yours says 10. I'm guessing you display 10 records per page.
recordsFiltered = total records after applying the filter (search).
This explanation was my missing point:) Thank you very much! it works now!