I'm paginating my results which are displayed through AJAX request but I'm facing a problem with the pagination. Here's my pagination logic:
if(reviews.pagination.next_page_url != null || reviews.pagination.current_page != 1) {
var paginat = "";
for (let p = 1; p <= reviews.pagination.last_page; p++) {
if (p === reviews.pagination.current_page) {
paginat = paginat + '<span aria-current="page"><b class="active">' + p + '</b></span>';
} else {
paginat = paginat + '<b>' + p + '</b>';
}
}
}
Here is an image what happens when the results are too many. How to minify this with ..
(dots) between the page numbers?
This is how I return pagination info:
return response()->json([
'pagination' => collect($reviews->toArray())->except('data'),
// ....
]);