i have a dropdown which has a number of options, and a table which is below that is connected to a dataset which will show products. i am trying to make it so when the user selects the value then presses the button it will then display the filtered results in the table.
the value i want to filter on, is a reference field called 'modelSuited' in my database. this is the following code snippet that i am working with at the minute:
when the button is pressed:
export function button3_click(event) { //Add your code for this event here: //filter($w("#ModelDropDown").value) db(); $w("#productTable").show(); }
function db (){ //var model = $w("#ModelDropDown"); $w("#dataset1").setFilter( wixData.filter() .contains('modelSuited', $w("#ModelDropDown"))) .then( (results) => { console.log("Dataset is now filtered"); let items = results.item; // This is now the filtered items $w("#productTable").rows = items; } ) .catch( (err) => { console.log(err); } ); }
when i then press the button on preview mode i get the following error:
Error: Failed to build a filter. Invalid .contains parameter value [Object]. .contains parameter must be a String..
i have also tried .eq/.hasSome to try and get it to work but doesnt seem to be playing ball.
i can change the query to pass in a "string" e.g hard code it for test purposes and get the following:
Dataset is now filtered
TypeError: Cannot read property 'item' of undefined
if anyone could help me out the achieve filtering on the reference field to match the product with the model, that would be great. thanks
#dropdown #filter #database #query #queryonvalue
update* i can make it work using the title field instead of reference field. so seems to be a problem with the reference field.