Hi there Velo Coders,
I’m seeking your wisdom to achieve a filter using multiple selection tags for a song catalogue. I’ve read through many posts but have not yet found a solution.
Here is the index of tags at the page header. Each row has its own ID.
And here is how they are organised in the data collection, as individual tag categories
I would like to code my page to filter the songs in the repeater using the range of fields - by:
- season, 2. liturgy, 3. sacrament, 4. saints 5. artist
With the values listed in the rows as displayed in the index above - currently set-up as 5 separate selection tag groups.
I’ve managed to get just one field working. How can I get the other fields interacting? Of course I could put all the values into one field and use one selection tag group - and might have to do this - but a work around will allow me to keep the page layout set-up in neat categorised rows and the dataset collection with multiple fields helps with some practicalities
I’d also like for the repeater to be hidden and appear when tags are selected.
Any thoughts? Here is the code:
import wixData from ‘wix-data’ ;
const collectionName = ‘Songs’ ;
const fieldToFilterByInCollection = ‘season’ ;
$w . onReady ( function () {
setRepeatedItemsInRepeater ()
loadDataToRepeater ()
$w ( '#selectionTags1' ). onChange (( event ) => {
const selectedTags = $w ( ‘#selectionTags1’ ). value
loadDataToRepeater ( selectedTags )
})
});
function loadDataToRepeater ( selectedCategories = ) {
let dataQuery = wixData . query ( collectionName );
if ( selectedCategories . length > 0 ) {
dataQuery = dataQuery . hasSome ( fieldToFilterByInCollection , selectedCategories );
}
dataQuery
. find ()
. then ( results => {
const itemsReadyForRepeater = results . items ;
$w ( ‘#repeater1’ ). data = itemsReadyForRepeater ;
const isRepeaterEmpty = itemsReadyForRepeater . length === 0
})
}
function setRepeatedItemsInRepeater ( ) {
$w ( ‘#repeater1’ ). onItemReady (( $item , itemData ) => {
$item ( '#image' ). src = itemData . image ;
$item ( '#image' ). tooltip = itemData . image ;
$item ( '#title' ). text = itemData . title
})
}