Reputation: 23
I implemented infinite scroll jquery plugin manually on my drupal website. I'm having an issue with a view that contains an exposed filter. Infinite scroll just keeps appending the same data.
For e.g: If at the time of page load our next page is "page=2" and last page is 5, in this case it simply appends the results of "page=2" to current results.
The "nextSelector"(.pager-next) points only to the next page in drupal. So the script loads the next page (e.g:page 2) over and over.
$container.infinitescroll({
navSelector : \'div.item-list ul.pager\', // selector for the paged navigation
nextSelector : \'div.item-list li.pager-next > a\', // selector for the NEXT link (to page 2)
itemSelector : \'.item\', // selector for all items you\'ll retrieve
bufferPx: 300,
pixelsFromNavToBottom: \'ul.pager\',
loading: {
msgText: \''.t('Loading More...').'\',
finishedMsg: \''.t('No more posts.').'\',
},
state: {
isDuringAjax: false,
isInvalidPage: false,
isDestroyed: false,
isDone: false, // For when it goes all the way through the archive.
isPaused: false,
currPage: 0
},
Upvotes: 0
Views: 1066
Reputation: 245
Drupal doesn't numbers pages as wordpress (infinite-scroll initial use) and its paging system return results if the request page doesn't exist (closest guess).
Add this settings :
$container.infinitescroll({
(...)
maxPage : 10 // your pager max pages or see below
state: {
currPage: 0
},
(...)
If you can't set the max pages into the javascript you could "hack" Drupal so it doesn't return any results if the page is out of bounds :
$perPage = 10;
$total = count($results);
$qs_page = isset($_GET['page']) ? $_GET['page'] : 0;
$page = pager_default_initialize($total, $perPage, 0);
if ($qs_page > $page) {
//out of bounds !!!
$perPage=0;
}
$offset = $perPage * $page;
$results = array_slice($results, $offset, $perPage,TRUE);
Upvotes: 1
Reputation: 23
The issue was not related to the infinite scroll plugin. It was a problem with the url generated by Drupal.
Upvotes: 0