Answer the question
In order to leave comments, you need to log in
How to write a competent single ajax-pagination on the site?
Good day everyone!
In fact, I wrote a single ajax pagination for the site, but it has 1 rather unpleasant jamb. I will describe in more detail below.
1. I added a new class to the pagination block - ajax-pagination.
2. Using jquery, I wrote an event and a function for working with pagination.
$body.on('click', '.ajax-pagination .paginate a', function (e) {
e.preventDefault();
let url = $(this).attr('href'),
$paginateBlock = $(this).closest('.list-paginated-items');
paginationChangePage(url, $paginateBlock);
window.history.pushState('', '', url);
});
function paginationChangePage(url, $paginateBlock)
{
$.ajax({
type: 'get',
url: url,
success: function (result) {
$paginateBlock.html(result);
$('html, body').animate({
scrollTop: $paginateBlock.offset().top
}, 500);
$(window).off('popstate').on('popstate', function () {
paginationChangePage(location.href, $paginateBlock);
});
}
});
}
if (request()->ajax()) {
return view('modules.chat.includes.messages', [
'messages' => $messages
])->render();
} else {
return view('modules.chat.index', [
'messages' => $messages,
'title' => 'Чат'
]);
}
Answer the question
In order to leave comments, you need to log in
As an option try the package: https://laravel-livewire.com/docs/pagination/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question