[SOLVED] Table won't display filter change

I have a page with a dropdown displaying items from one dataset, and a table displaying data from another dataset. I’m trying to write the code that will filter the table based on the value chosen in the dropdown.

I have the following code, but it doesn’t seem to redisplay the table. I’m new to coding with Wix (though I was a programmer in VB years ago), but I’m stumped. I can’t even figure out how to print out the value of the variable so I can see if it’s getting the correct data, and the debugging is way over my head these days! (LOL!) Please help! What am I doing wrong? Thanks!

$w.onReady( function () {
//TODO: write your page related code here…

});
import wixData from ‘wix-data’;

export function dropdown1_change(event) {
//Sets filter based on dropdown change:
let selectedValue = $w(“#dropdown1”);
$w(“#dataset1”).setFilter(
wixData.filter().eq(‘usedFor’, selectedValue));
}

Hello

  • Check this out to know how to get a drop down value. and this to set a filter to the tables data set.
  • to print out the value of the variable so I can see if it’s getting the correct data use console.log()

Massa

Thanks Massa,

I figured out the problem:
The value returned included everything in the dropdown, so I had to then refine the variable by drilling down to the .value, which then returned only the string that was the dropdown’s selection.

Here is the full code. The only thing that is new is that I added the

//import wixData from ‘wix-data’;
import wixData from ‘wix-data’;

//function to get the dropdown selection and run a filter with that selection to reset the table
export function dropdown1_change(event) {
//get the selected item in the dropdown (but this returns all the properties of the dropdown)
let selectedValue = $w(‘#dropdown1’);
// get just the string that is listed as the .value property of the dropdown, ie “Left Hand - Shape”

//NEW LINE OF CODE
let myValue=selectedValue.value;

//Sets filter based on dropdown change:
$w(“#dataset1”).setFilter(
// REVISED: use the myValue variable in the filter parameters instead of selectedValue
// wixData.filter().eq(‘usedFor’, selectedValue)); }
wixData.filter().eq(‘usedFor’, myValue));
}