Skip to content
Snippets Groups Projects
Commit 20d1e741 authored by Bitha17's avatar Bitha17
Browse files

fix: pagination

parent dbd157d1
Branches master
No related merge requests found
Pipeline #59405 failed with stages
......@@ -25,7 +25,9 @@
} else {
$pembelians = $pembelianController->getAllPembelianWithDetails();
}
$paginationData = $pembelianController->paginateHistory($pembelians);
$pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10;
$paginationData = $pembelianController->paginateHistory($pembelians,$_GET['page'],$pageSize);
$pembelians = $paginationData['pembelian'];
$totalEvents = $paginationData['total'];
$currentPage = $paginationData['page'];
......@@ -61,18 +63,30 @@
endforeach;?>
</div>
<div class="pagination">
<?php if ($currentPage > 1) : ?>
<a href="?page=<?= $currentPage - 1 ?>">Previous</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $maxPage; $i++) : ?>
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a>
<?php endfor; ?>
<?php if ($currentPage < $maxPage) : ?>
<a href="?page=<?= $currentPage + 1 ?>">Next</a>
<?php endif; ?>
</div>
<?php
$searchParams = [
'search' => $searchQuery,
'min_stock' => $minStock,
'sort' => $sortKey,
'pageSize' => $pageSize, // Include page size
];
$maxButtons = 5; // Maximum number of pagination buttons to display
$halfMaxButtons = floor($maxButtons / 2);
if ($currentPage > 1) : ?>
<a href="?page=<?= $currentPage - 1 ?>">Previous</a>
<?php endif; ?>
<?php
for ($i = max(1, $currentPage - $halfMaxButtons); $i <= min($maxPage, $currentPage + $halfMaxButtons); $i++) : ?>
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a>
<?php endfor; ?>
<?php if ($currentPage < $maxPage) : ?>
<a href="?page=<?= $currentPage + 1 ?>">Next</a>
<?php endif; ?>
</div>
</div>
......
......@@ -28,7 +28,9 @@
if (!isset($_GET['page'])) {
$_GET['page'] = 1;
}
$paginationData = $eventController->paginateEvents($searchResults,$_GET['page']);
$pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10;
$paginationData = $eventController->paginateEvents($searchResults,$_GET['page'],$pageSize);
$events = $paginationData['events'];
$totalEvents = $paginationData['total'];
$currentPage = $paginationData['page'];
......@@ -81,18 +83,32 @@
endforeach;?>
<div class="pagination">
<?php if ($currentPage > 1) : ?>
<a href="?page=<?= $currentPage - 1 ?>">Previous</a>
<?php
$searchParams = [
'search' => $searchQuery,
'min_stock' => $minStock,
'sort' => $sortKey,
'pageSize' => $pageSize, // Include page size
];
$maxButtons = 5; // Maximum number of pagination buttons to display
$halfMaxButtons = floor($maxButtons / 2);
if ($currentPage > 1) : ?>
<a href="?page=<?= $currentPage - 1 . '&' . http_build_query($searchParams) ?>">Previous</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $maxPage; $i++) : ?>
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a>
<?php
for ($i = max(1, $currentPage - $halfMaxButtons); $i <= min($maxPage, $currentPage + $halfMaxButtons); $i++) : ?>
<a href="?page=<?= $i . '&' . http_build_query($searchParams) ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a>
<?php endfor; ?>
<?php if ($currentPage < $maxPage) : ?>
<a href="?page=<?= $currentPage + 1 ?>">Next</a>
<a href="?page=<?= $currentPage + 1 . '&' . http_build_query($searchParams) ?>">Next</a>
<?php endif; ?>
</div>
</div>
</div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment