Hi Everyone, please, I need hep wit this piece of code. The filter should run through dataset and give the result of the product matching category, name, and capacity(Numbers). When I go on find product the repeater disappears but it works when I delete this line from the code .contains("capacity", $w('#dropdown3').value)) !
CODE
export function findProduct_click(event, $w) { $w("#dataset1").setFilter(wixData.filter() .contains("category", $w('#dropdown1').value) .contains("displayName", $w('#dropdown2').value) .contains("capacity", $w('#dropdown3').value)) .then( () => { getItems() .then( (results) => { $w('#repeater3').data = results.items; }); }); } function getItems() { return $w("#dataset1").getItems(0, 1000) .then( (result) => { return result; }); }
Solved with .ascending() ! Thanks Kristof :)
Adding a sorting option to the query and sorting the collection on Database is not working. I am now trying to find out where to add the piece of code you gave and will let you know :). Thanks!
Guys sorry to bother you again, but is there a way to sort the content of my dropdown3, these are numbers and I would like to have them sorted.
Thank you Kristof, you helped me more than enough. Thanks mate!
It worked!!! I changed parseInt with Number and it worked like a charm! I cannot thank you enough guys! I love this forum.
Anime, to add here whilst Kristof is away and can't help at the moment.
Note that the eq() function won't match if you are using two different types.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#eq
It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.
As you are using parseInt here, check what you are using with your dropdown and dataset fields otherwise you are trying to match a number to a string or a string to a number for example.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
With Kristof code sample try removing the parseInt from the eq line and see if that works.
.eq("capacity", parseInt($w('#dropdown3').value)))) //will be// .eq("capacity", ($w('#dropdown3').value))))
If you are getting the radix error in the yellow triangle on this line, you can look at trying using Number() instead of parseInt()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
See here for more info on the differences between them in this old Stack post here.
https://stackoverflow.com/questions/4090518/what-is-the-difference-between-parseint-and-number/4090577#4090577
If none of the above works for you, then please wait until Kristof can get back onto your site to help you with it further. 👍
Hi Kristof, strangely does not work for me. I did exactly what you said. Would you mind saving it if it worked for you ? Thank you very much for your help :)
Thank you very much!! That's really kind of you. Invite is on the way.
Still nothing. Only difference the repeater does not disappear but it does not load any product. Filter did not pass through.
I thought maybe I show you the entire code. How I want it to work : there are 3 dependant dropdown menus, 2 are disabled onReady. When first dropdown gets a value second is enabled. Same goes for third which is dependant on second dropdown. Once all values are set, user clicks on Find and the respective filtered product will be extracted from dataset and displayed on the repeater. Now everything works fine, until the third dropdown which contains numbers on my dataset seems to "refuse" giving its value to the filter code (my own assumption). FYI : When I take out the piece of code for the third dropdown everything works fine and products are found. Code :
import wixData from 'wix-data'; $w.onReady(function () { uniqueDropDown1(); }); function uniqueDropDown1() { wixData.query("PackagingSolutions") .limit(1000) .find() .then(results => { const uniqueTitles = getUniqueTitles(results.items); $w("#dropdown1").options = buildOptions(uniqueTitles); }); function getUniqueTitles(items) { const titlesOnly = items.map(item => item.category); return [...new Set(titlesOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return { label: curr, value: curr }; }); } } export function dropdown1_change(event) { uniqueDropDown2(); $w("#dropdown2").enable(); } function uniqueDropDown2() { wixData.query("PackagingSolutions") .contains("category", $w("#dropdown1").value) .limit(1000) .find() .then(results => { const uniqueTitles = getUniqueTitles(results.items); $w("#dropdown2").options = buildOptions(uniqueTitles); }); function getUniqueTitles(items) { const titlesOnly = items.map(item => item.displayName); return [...new Set(titlesOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return { label: curr, value: curr }; }); } } export function dropdown2_change(event) { uniqueDropDown3(); $w("#dropdown3").enable(); } function uniqueDropDown3() { wixData.query("PackagingSolutions") .contains("category", $w("#dropdown1").value) .limit(1000) .find() .then(results => { const uniqueTitles = getUniqueTitles(results.items); $w("#dropdown3").options = buildOptions(uniqueTitles); }); function getUniqueTitles(items) { const titlesOnly = items.map(item => String(item.capacity)); return [...new Set(titlesOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return { label: curr, value: curr }; }); } } export function findProduct_click(event, $w) { $w("#dataset1").setFilter(wixData.filter().contains("category", $w('#dropdown1').value).and(wixData.filter().contains("displayName", $w('#dropdown2').value)).and(wixData.filter() .contains("capacity", $w('#dropdown3').value))) .then(() => { getItems() .then((results) => { $w('#repeater3').data = results.items; }); }); } function getItems() { return $w("#dataset1").getItems(0, 1000) .then((result) => { return result; }); }
Hi Kristof, the field value from the dataset is totally correct and matching with the respective code part. I think the problem goes beyond that also.
Thank you very much Kristof, unfortunately the new code did not fix it. I believe there is a problem with the code being able to extract/read the info from "capacity" dropdown (maybe because it's numbers) ? I don't get any error message on debug, the repeater just disappears. Please bare with me :)
Oke i'll correct it how i think it should work.
exportfunction findProduct_click(event, $w) { $w("#dataset1").setFilter(wixData.filter() .contains("category", $w('#dropdown1').value) .and(wixdata.filter().contains("displayName", $w('#dropdown2').value)) .and(wixData.filter() .contains("capacity", $w('#dropdown3').value))) .then( () => { getItems() .then( (results) => { $w('#repeater3').data = results.items; }); });} function getItems() { return $w("#dataset1").getItems(0, 1000) then( (result) => { return result; }); }
i think this should work.
kind regards
Kristof.
Sorry Kristof but I am new to coding and I don't understand what to replace exactly to make this work. Can you please help me more ? Thanks
Hi AMINE,
instead of using .contains().contains().contains() look here to work with .and()
kind regards
Kristof.