I use framework v4 and added virtual list with infinite scroll. This works fine until I am scrolled al the way down and want to go up realy fast. Nothing is displayed anymore and the user needs to close and open the app to continue.
// Virtual List
VLViewRecords = f7app.virtualList.create({
el: ".VLViewRecords",
items: $.parseJSON(LastRecords),
searchAll: function (query, items) {
var found = [];
for (var i = 0; i < items.length; i++) {
if (items[i].name.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') found.push(i);
}
return found;
},
itemTemplate:
'<li data-dbid="{{dbid}}">'+
'<a href="{{url}}" class="item-link item-content">'+
'<div class="item-media"><img src="{{img}}" class="badge-mdsmall"></div>'+
'<div class="item-inner">'+
'<div class="item-title">'+
'{{name}}'+
'<div class="item-header">{{date}}</div>'+
'</div>'+
'<div class="item-after">{{score}}</div>'+
'</div>'+
'</a>'+
'</li>',
height: 88 // Height of items
});
// Remove preloader below ten items
if ($.parseJSON(LastRecords).length < 10) {
$("#view-records .infinite-scroll-preloader").addClass("hidden");
}
And how I fill infinite scroll:
// Infinite Scroll
// Loading flag
var allowInfinite = true;
// View Records
// Set Start Number
var VLViewRecordsNum = 10; // First LoadLastRecords loaditem = Startnumber
var VLViewRecordsLoadItems = 10;
// Attach 'infinite' event handler
$$('#view-records .infinite-scroll-content').on('infinite', function () {
// Exit, if loading in progress
if (!allowInfinite) return;
// Set loading flag
allowInfinite = false;
// Set variable to wait for items
WaitLastRecords = 0;
// Emulate 1s loading
setTimeout(function () {
// Reset loading flag
allowInfinite = true;
// Parse Array
var ArrLastRecords = $.parseJSON(LastRecords);
// Load Items, start after last timestamp
LoadLastRecords(localStorage.getItem('Session'),sessionmeasure,VLViewRecordsLoadItems,"Load",ArrLastRecords[ArrLastRecords.length - 1].timestamp,localStorage.getItem('Lang'));
// Period check if items are loaded
var Interval = window.setInterval(function(){
// If loading is done
if (WaitLastRecords === 1) {
// Stop checking
clearInterval(Interval);
// If no items are returned exit infinite scroll
if (LastRecords === "null") {
// Nothing more to load, detach infinite scroll events to prevent unnecessary loadings
f7app.infiniteScroll.destroy('#view-records .infinite-scroll-content');
// Remove preloader
$$('.infinite-scroll-preloader').remove();
return;
} else {
// Append new items to Virtual List
VLViewRecords.appendItems($.parseJSON(LastRecords));
// Change Startnumber for next load
VLViewRecordsNum = VLViewRecordsNum + VLViewRecordsLoadItems;
// Show scroll if hidden
$("#view-records .infinite-scroll-preloader").removeClass("hidden");
}
}
}, 1000);
}, 1000);
});
Thanks, but i’ve checked and my list item is exactly 88px height. List item is 86px with 2px margin at the bottom. When I change the virtuallist height parameter to 86 the whole list is displayed incorrect.
Please tell me where I open more than one? I believe I use it one time only and only in this view. I really need to have this fixed. I used the example from framework7 page.
I notice only 32 items are in virtual list. When I scroll down and reach 32 items the first items get removed and the next items load. There are only 32 items shown in html. Is this normal behavior for the virtual list?
Should the first items appear when I scroll back up or do I have to code this?
Just solved my issue by changing the virtual list to a simple list. It did not work for me with a virtual list because the top items are removed when scrolling.