data filtering only happens in first virtual list only which was inside the first tab, when i switch to second tab then it shows nothing found
The reason is that a searchbar
is initialized with the CSS selector searchContainer
option when you create it via app.searchbar.create({ searchContainer: '.virtual-list' })
. It does not evaluate the CSS selector searchContainer
option again and update its properties before you start a search.
I am new to Framework7. Have used it for a few days and I come up with a web design similar to yours.
So my web app is a single index.html file based on the only Single View template provided by the official Framework7 website.
https://framework7io.github.io/framework7-template-single-view/
I have changed it to have a single searchbar on the navbar of the view-main
page.
I have changed it to have a Swipeable Tabs component on the view-main
page.
Inside each tab, there is a page with page-content
of a Virtual List.
To summarize, I have 1 searchbar
, 10 tab
s and every tab has 1 virtual list.
I expect the behavior of the searchbar
is to search all .item-title span
under the .tab-active
tab.
So in my JavaScript, I have:
var searchbar = app.searchbar.create({
el: '.searchbar',
searchContainer: '.virtual-list', // init: virtual list on the 1st active tab
searchIn: '.item-title span',
on: {
search(sb, query, previousQuery) {
// ... your own logic
}
}
});
$$('a.tab-link').on('click', function() {
tabChange();
});
app.on('tabShow', function(tabEl) {
tabChange();
});
function tabChange() {
searchbar.$searchContainer = $$('.tab-active .virtual-list');
searchbar.searchContainer = searchbar.$searchContainer[0];
}
So when I swipe between tabs or click on a tab button, the tabChange()
function will be triggered to set the searchContainer
and $searchContainer
properties of the only searchbar
. It is what you need to change the search target.