Hello.
I am working on a website for the sale of real estate. I need to sort real estate by several parameters. At the moment, I am filtering properties by number of rooms, district and property value. Right now the code only works if you select options in all the dropdowns. That is, if I select only the required number of rooms and press the filter button, the console will give an error:
Error: Failed to perform query on [Apartments].
WDE0058: $ gte should be a Date, Number, or String. Got null instead
WDE0058: $ lt should be a Date, Number, or String. Got null instead
I would like to know if it is possible to filter the data individually.
Code:
import wixData from 'wix-data'; export function button2_click(event, $w) { $w("#dataset1").setFilter(wixData.filter() .eq("1", Number($w('#dropdown1').value)) .contains("district", String($w('#dropdown2').value))
.between("testprice",parseFloat($w('#dropdown3').value), parseFloat($w('#dropdown4').value))) .then((results) => { console.log("Dataset is now filtered"); $w("#repeater1").data = results.items; }).catch((err) => { console.log(err); }); $w("#repeater1").expand(); }
But I've got repeater. Is it this changing enough?
$w.onReady(async()=>{ $w('#button14').onClick(()=>{ wixData.query("TumIlanlar") .between("fiyat", Number($w('#input1').value), Number($w('#input2').value)) .find() .then( (results) => { if(results.items.length > 0) { let items = results.items; console.log(items) $w('#propertyList').data = items } else { } }) .catch( (error) => {console.log(error)}); }); });
You can do it the same way like it is already show in this example...
...where you can search between 2 values.
https://www.wix.com/velo/reference/wix-data/wixdatafilter/between
Thank. I will definitely try. One more question. Is it possible to set up price filtering based on the entered data? That is, so that the user can enter the amount himself and filter it.
ты ищешь... ??? (searching for ???)...
https://russian-dima.wixsite.com/wixworld/nedvizhimost
https://russian-dima.wixsite.com/wixworld/nedvizhimost-iiii
https://www.media-junkie.com/pflegeservice ---> DB-Preset-2
And YES! It is possible as like you want it to be.
EDIT: Боже мой, нашел свой старый CODE 😅 (found my very beginning CODE for a filter)
It looks like this, when you start with coding 😅🤣, what a crazy code.
import wixData from 'wix-data'; $w.onReady(function () { //TODO: write your page related code here... }); export function DD1_change(event) {SEARCH_ENGINE()} export function DD2_change(event) {SEARCH_ENGINE()} export function DD3_change(event) {SEARCH_ENGINE()} export function DD4_change(event) {SEARCH_ENGINE()} export function DD5_change(event) {SEARCH_ENGINE()} export function input1_change(event) {SEARCH_ENGINE()} export function input2_change(event) {SEARCH_ENGINE()} export function BTNtest_click(event) {SEARCH_ENGINE()} function SEARCH_ENGINE() {console.log("Serchengine started!") var input1 = $w("#input1").value var input2 = $w("#input2").value var item1, item2, item3, item4, item5 var column1, column2, column3, column4, column5 var CODE = "" console.log(input1) console.log(input2) if ($w('#DD1').value!=0){column1 = "item1", item1 = $w('#DD1').value, CODE=CODE + "1"} else{CODE=CODE + "0"} if ($w('#DD2').value!=0){column2 = "item2", item2 = $w('#DD2').value, CODE=CODE + "1"} else{CODE=CODE + "0"} if ($w('#DD3').value!=0){column3 = "item3", item3 = $w('#DD3').value, CODE=CODE + "1"} else{CODE=CODE + "0"} if ($w('#DD4').value!=0){column4 = "item4", item4 = $w('#DD4').value, CODE=CODE + "1"} else{CODE=CODE + "0"} //special-item-search (item5) if ($w('#input1').value!=0 || $w('#input2').value!=0){column5 = "item5", item5 = $w('#DD5').value, CODE=CODE + "1"} else{CODE=CODE + "0"} //ABFRAGE----------------------------------------------CODE-ZERO console.log(CODE) if (CODE=="00000"){$w("#dataset1").setFilter(wixData.filter())} //ABFRAGE----------------------------------------------Einzeln if (CODE=="10000"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1));} if (CODE=="01000"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2));} if (CODE=="00100"){$w("#dataset1").setFilter(wixData.filter().eq(column3, item3));} if (CODE=="00010"){$w("#dataset1").setFilter(wixData.filter().eq(column4, item4));} if (CODE=="00001"){$w("#dataset1").setFilter(wixData.filter().between(column5, input1, input2));} //ABFRAGE----------------------------------------------Duo if (CODE=="11000"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2));} if (CODE=="01100"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2).eq(column3, item3));} if (CODE=="00110"){$w("#dataset1").setFilter(wixData.filter().eq(column3, item3).eq(column4, item4));} if (CODE=="00011"){$w("#dataset1").setFilter(wixData.filter().eq(column4, item4).between(column5, input1, input2));} if (CODE=="10100"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column3, item3));} if (CODE=="10010"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column4, item4));} if (CODE=="10001"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).between(column5, input1, input2));} if (CODE=="01001"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2).between(column5, input1, input2));} if (CODE=="00101"){$w("#dataset1").setFilter(wixData.filter().eq(column3, item3).between(column5, input1, input2));} if (CODE=="01010"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2).eq(column4, item4));} //ABFRAGE----------------------------------------------Trio if (CODE=="11100"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).eq(column3, item3));} if (CODE=="11010"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).eq(column4, item4));} if (CODE=="11001"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).between(column5, input1, input2));} if (CODE=="10101"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column3, item3).between(column5, input1, input2));} if (CODE=="10011"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column4, item4).between(column5, input1, input2));} if (CODE=="01011"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2).eq(column4, item4).between(column5, input1, input2));} if (CODE=="00111"){$w("#dataset1").setFilter(wixData.filter().eq(column3, item3).eq(column4, item4).between(column5, input1, input2));} if (CODE=="10110"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column3, item3).eq(column4, item4));} if (CODE=="01110"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2).eq(column3, item3).eq(column4, item4));} //ABFRAGE----------------------------------------------Quadro if (CODE=="11110"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).eq(column3, item3).eq(column4, item4));} if (CODE=="11101"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).eq(column3, item3).between(column5, input1, input2));} if (CODE=="11011"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).eq(column4, item4).between(column5, input1, input2));} if (CODE=="10111"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column3, item3).eq(column4, item4).between(column5, input1, input2));} if (CODE=="01111"){$w("#dataset1").setFilter(wixData.filter().eq(column2, item2).eq(column3, item3).eq(column4, item4).between(column5, input1, input2));} //ABFRAGE----------------------------------------------X5 if (CODE=="11111"){$w("#dataset1").setFilter(wixData.filter().eq(column1, item1).eq(column2, item2).eq(column3, item3).eq(column4, item4).eq(column5, item5)); } console.log($w('#DD1').value) console.log($w('#DD2').value) console.log($w('#DD3').value) console.log(CODE) }
But here you should find a much better method how to code a filter....
https://www.wix.com/velo/forum/community-discussion/database-filtering-and-grouping-including-caching-of-results