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 @@ ...@@ -25,7 +25,9 @@
} else { } else {
$pembelians = $pembelianController->getAllPembelianWithDetails(); $pembelians = $pembelianController->getAllPembelianWithDetails();
} }
$paginationData = $pembelianController->paginateHistory($pembelians); $pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10;
$paginationData = $pembelianController->paginateHistory($pembelians,$_GET['page'],$pageSize);
$pembelians = $paginationData['pembelian']; $pembelians = $paginationData['pembelian'];
$totalEvents = $paginationData['total']; $totalEvents = $paginationData['total'];
$currentPage = $paginationData['page']; $currentPage = $paginationData['page'];
...@@ -61,18 +63,30 @@ ...@@ -61,18 +63,30 @@
endforeach;?> endforeach;?>
</div> </div>
<div class="pagination"> <div class="pagination">
<?php if ($currentPage > 1) : ?> <?php
<a href="?page=<?= $currentPage - 1 ?>">Previous</a> $searchParams = [
<?php endif; ?> 'search' => $searchQuery,
'min_stock' => $minStock,
<?php for ($i = 1; $i <= $maxPage; $i++) : ?> 'sort' => $sortKey,
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a> 'pageSize' => $pageSize, // Include page size
<?php endfor; ?> ];
<?php if ($currentPage < $maxPage) : ?> $maxButtons = 5; // Maximum number of pagination buttons to display
<a href="?page=<?= $currentPage + 1 ?>">Next</a> $halfMaxButtons = floor($maxButtons / 2);
<?php endif; ?>
</div> 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> </div>
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
if (!isset($_GET['page'])) { if (!isset($_GET['page'])) {
$_GET['page'] = 1; $_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']; $events = $paginationData['events'];
$totalEvents = $paginationData['total']; $totalEvents = $paginationData['total'];
$currentPage = $paginationData['page']; $currentPage = $paginationData['page'];
...@@ -81,18 +83,32 @@ ...@@ -81,18 +83,32 @@
endforeach;?> endforeach;?>
<div class="pagination"> <div class="pagination">
<?php if ($currentPage > 1) : ?> <?php
<a href="?page=<?= $currentPage - 1 ?>">Previous</a> $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 endif; ?>
<?php for ($i = 1; $i <= $maxPage; $i++) : ?> <?php
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a> 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 endfor; ?>
<?php if ($currentPage < $maxPage) : ?> <?php if ($currentPage < $maxPage) : ?>
<a href="?page=<?= $currentPage + 1 ?>">Next</a> <a href="?page=<?= $currentPage + 1 . '&' . http_build_query($searchParams) ?>">Next</a>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </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