Hello community!
I’m having a little issue searching items from a Virtual-List. I’m loading a 4200 plus items on the list and it’s like it’s only searching on the first 40 items and doesn’t care about the rest. Why does that happen?. And when scrolling looks good and all. Also I notice when I inspect the elements with the browser while I scroll down the list items are being “created” or “loaded” on the html. What I want to do is that the searchbar search on all the items on the virtual-list. I’ll post some code. Thanks in advance.
EDIT: Here’s live example https://jsfiddle.net/8ua5tewh/1/
Try searching the name Zweiger, for example and doesn’t work. It only search from 0 to 39.
Here’s the JS function for the Virtual-List
function cargarListaPacientes(idClinica) {
var urlPacientes = "myjsonurl.com";
app.preloader.show();
app.request.get(urlPacientes, function(data) {
var dataPacientes = JSON.parse(data);
console.log(dataPacientes);
var virtualListPacientes = app.virtualList.create({
// List Element
el: '.virtual-list-pacientes',
// Pass array with items
items: dataPacientes.pacientes,
// Custom search function for searchbar
searchAll: function (query, items) {
var found = [];
for (var i = 0; i < items.length; i++) {
console.log(items[i]);
if (items[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') found.push(i);
}
return found; //return array with mathced indexes
},
// List item Template7 template
itemTemplate:
'<li data-id="{{dni}}" data-nombre-paciente="{{nombre}}">' +
'<a href="#" class="item-link item-content">' +
'<div class="item-inner">' +
'<div class="item-title-row">' +
'<div class="item-title">{{nombre}}</div>' +
'</div>' +
'<div class="item-subtitle">DNI: {{dni}}</div>' +
'</div>' +
'</a>' +
'</li>',
// Item height
height: app.theme === 'ios' ? 63 : 73,
});
app.preloader.hide();
});
}
Here’s the HTML code:
<div class="page" data-name="pacientes">
<!-- Navbar -->
<div class="navbar">
<div class="navbar-inner sliding">
<!-- Left -->
<div class="left sliding">
<a href="#" class="link back">
<i class="icon icon-back"></i>
<span class="ios-only">Atrás</span>
</a>
</div>
<!-- Title -->
<div class="title sliding">Pacientes</div>
<!-- Right -->
<div class="right">
<!-- Link to enable searchbar -->
<a class="link icon-only searchbar-enable" data-searchbar=".searchbar-pacientes">
<i class="icon f7-icons ios-only">search_strong</i>
<i class="icon material-icons md-only">search</i>
</a>
</div>
<!-- Searchbar is a direct child of "navbar-inner" -->
<form class="searchbar searchbar-expandable searchbar-init searchbar-pacientes"
data-search-container=".virtual-list-pacientes" data-search-item="li" data-search-in=".item-title">
<div class="searchbar-inner">
<div class="searchbar-input-wrap">
<input type="search" placeholder="Buscar pacientes"/>
<i class="searchbar-icon"></i>
<span class="input-clear-button"></span>
</div>
<span class="searchbar-disable-button">Cancelar</span>
</div>
</form>
</div>
</div>
<!-- Page Content -->
<div class="page-content">
<!-- Searchbar backdrop -->
<div class="searchbar-backdrop"></div>
<div class="list simple-list searchbar-not-found">
<ul>
<li>No se han encontrado resultados.</li>
</ul>
</div>
<!--Virtual List Pacientes-->
<div class="list virtual-list-pacientes media-list searchbar-found">
</div>
<!--Virtual List Pacientes-->
</div>
</div>