bjd
June 16, 2020, 8:49pm
1
For my TMT Realty website ( https://bdarienjr.wixsite.com/tmt-realty ), I am having problems with the code for filtering properties on the rentals page ( https://bdarienjr.wixsite.com/tmt-realty/rentals-1 ).
I keep getting an error saying that it could not resolve the dynamic filter (see screenshot #1 below). HOW DO I FIX THIS??
(See my code below)
import wixData from 'wix-data';
$w.onReady(function () {
});
let lastFilterTitle;
function filter(title) {
if (lastFilterTitle !== title) {
$w('#dynamicDataset').setFilter(wixData.filter()
.ne('offMarket', true)
.contains('title', title));
lastFilterTitle = title;
}
}
export function searchButton1_click_1(event) {
$w("#dynamicDataset").setFilter(wixData.filter()
.contains("neighborhoodSort", $w("#hoodsDD").value)
.ge("beds", Number($w("#bedsDD").value))
.ge("baths", Number($w("#bathsDD").value))
.le("sortRent", Number($w("#priceSlider1").value))
);
}
1 Like
function filter(title) never got called, is that supposed to attach to by any event handler? If so, it should be: export function filter(title)
It looks like you have used this example here, where they have functions and they are being called in the used code and tried to chop and change and adjust it to suit your own needs.
https://www.wix.com/corvid/example/search-a-database
https://www.wix.com/corvid/forum/tips-tutorials-examples/example-search-a-database
As mentioned already above by Ayleung, you are using a function here without anything calling it in the rest of your code.
Are you trying to do something like this tutorial here.
https://www.wix.com/corvid/example/mega-search
As you will notice that they too have used a function here…
function initRepeater() {
//rest of code//
However, they are calling that function in the pages onReady function…
$w.onReady(function () {
initComps();
initRepeater();
buildFiltersAndPopulateRepeater();
});
bjd
June 17, 2020, 2:46pm
4
I changed it to “export function filter(title)” and I still got the same error. Any other suggestions?
The goal is to filter out properties marked as “offMarket” along with all the other filter parameters
Where is the checkbox boolean value for the off market option coming from on your page?
If it is on the same page, then you can simply simply add an onChange event handler to the element used.
Then set code to filter the dataset to show only the off market properties only as you have done in your code.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#ne
$w("#dynamicDataset").setFilter(
wixData.filter().ne('offMarket', true)
).catch((err) => {
console.log(err);
});
If you are coming from another page and want to show the results with off market already done, then add that to your onReady page code.
Another option would be to change it to on market instead of off market and use eq instead of ne so that it only displays the onMarket ones only.
$w("#dynamicDataset").setFilter(
wixData.filter().eq('onMarket', true)
).catch((err) => {
console.log(err);
});
Or if you want it to be a variable option of either checked or unchecked, true or false, then use Wix Storage to save the chosen value and then get the chosen value on page load and set the dataset filter by that option.
bjd
June 17, 2020, 4:26pm
6
The checkbox boolean value is coming from the dynamic dataset on the page (Rentals dataset) - see screenshots below.
I adapted my code per your suggestion, and I am still receiving the same error:
An error occurred in one of currentIndexChanged callbacks DatasetError: could not resolve dynamic filter
At this point, neither the filter function works, nor does sorting out the “offMarket” properties. Here is my current code:
import wixData from 'wix-data';
$w.onReady(function () {
});
let lastFilterTitle;
export function filter(title) {
if (lastFilterTitle !== title) {
$w("#dynamicDataset").setFilter(
wixData.filter().ne('offMarket', true)
).catch((err) => {
console.log(err);
});
}
}
export function searchButton1_click_1(event) {
$w("#dynamicDataset").setFilter(wixData.filter()
.contains("neighborhoodSort", $w("#hoodsDD").value)
.ge("beds", Number($w("#bedsDD").value))
.ge("baths", Number($w("#bathsDD").value))
.le("sortRent", Number($w("#priceSlider1").value))
);
}
I am not sure whether this problem is resolved or not. Looks like it was reported a year ago. But I am getting the same error in my code. The site monitoring shows it is coming from velo. If you found out the problem please let me know how you resolved it. Thank you.
“jsonPayload”: { “message”:"An error occurred in one of currentIndexChanged callbacks DatasetError: could not resolve dynamic filter errorReporter@https://static.parastorage.com/services/dbsm-viewer-app/1.3606.0/app.js:1:248717 Se/<@https://static.parastorage.com/services/dbsm-viewer-app/1.3606.0/app.js:1:17931 "
}
“receiveTimestamp”:“2021-06-11T15:41:33.058Z”