I understand wixBooking, wixStore, and wixEvents could need a read-only collection, but why simple field cannot be filtered ?
For exemple, if i want to filter a booking/service, with the field “TagLine” which is a text, i can’t !
But i can sort by price (not filter), or filter by pricing plan (and not sort).
That is really really limited, and i don’t even know why ! (in term of security)
Can you show us the error that you get? I have never encountered this error before.
Got it. It seems weird, you are right. One solution is to get the collection you need, filtered and then sort it out later, in an array of objects.
@bwprado Well yeah, but i mean, doing a fixed copy of a already existing data collection is a bit odd…
@edouard I understand, but without knowing what you need, I cannot think anything differently. It wouldn’t be a whole fixed copy, but one that was already filtered. It would make the app faster also.
@bwprado i just want to filter a repeater by the tagLine field (or by a field that as specificities, like strategy games, or else) to make kind of “categories” showing up in a repeater !
This is what I got for you:
After you retrieve the data from the Collection you want, you can filter it, anyway you like it, it is going to be just a regular object. Like this:
aimport wixData from "wix-data"
$w.onReady(async () => {
//Stores all services in this variable
const allServices = await getServices()
//Defines repeater as a variable, you can change the element to yours
const repeater = $w("#repeater1")
//Stores feeded initial Repeater Data, its not going to be used again unless page is reloaded
const repeaterData = feedRepeater(repeater, allServices)
//Created a button that filters the Repeater with the word "Velo" as my example collection had a tagLine with that word
$w("#button2").onClick(() => {
let filterRepeaterData = filterDataInRepeater(repeater, "Velo")
let updatedRepeater = feedRepeater(repeater, filterRepeaterData)
})
})
//Gets all services on Bookings Collection
const getServices = async () => {
let results = await wixData.query("Bookings/Services").find()
console.log(results)
return results.items
}
//Feed the data to the repeater
const feedRepeater = (repeater, fillData) => {
repeater.data = fillData
repeater.forEachItem(($item, itemData, index) => {
$item("#textRepeater").text = itemData.tagLine
$item("#textRepeaterTitle").text = itemData.serviceName
})
}
//Filter data in repeater
const filterDataInRepeater = (repeater, filterWord) => {
filterWord = filterWord.toLowerCase()
const filteredData = repeater.data.filter(item => item.tagLine.toLowerCase().includes(filterWord))
return filteredData
}