Showing Multiple Filtered Results in Text Fields

The code I have below filters out the item number for the color red items. The filter Is by size, weight, and height. The results for red are shown in a “text1”. In my database the values are Item Number, Size, Weight, Height, and color. (This code works)

import wixData from ‘wix-data’ ;
$w.onReady( function () {
});
export function button1_click(event, $w) {
$w( ’ #dataset1 ’ ).setFilter(wixData.filter()
.eq( “color” , “red” )
.eq( “size” , $w( ’ #dropdown1 ’ ).value)
.contains( “weight” , $w( ’ #dropdown2 ’ ).value)
.contains( “height” , $w( ’ #dropdown3 ’ ).value)
)
$w( ’ #text 1’ ).expand();
}

(Currently)

What I would like to do is add another text field where the green colored item numbers are shown when the drop downs are selected and the button is initiated. So after a user selects the drop downs size,weight, and height. The item number will show for red in a “text1” but also show for green in “text2”. What do I need to add to my code for the green colored results to be shown?

(What I would like it to be)

Any help will be greatly appreciated!

Hi,

depending on the situation, there are two ways to go about it.

Alternative 1.

If you know the number of alternatives you need (say green and red), you can just add label for everyone and prefill them the same way you do know.

Add another label and another dataset assigning a similar filter based on the same field.

Alternative 2.

This one scales better with the number of options you have.

  1. Instead of just using a single label, put that label to the repeater and bind the dataset to the label in the reapeater.

  2. Omit the filter for color, so that dataset will get all colors or change the color part from .eq(‘color’, ‘red’) to list the colors you need .hasSome(‘color’, [‘red’, ‘green’])

This way you can display any number of options fairly easily.

More details:
https://support.wix.com/en/article/about-displaying-database-content-in-a-repeater

Hope this helps.

I would rather not use a repeater on what I am doing. I want the item number to be displayed in a text field. Can you elaborate more with Alternative 1 please, I am having a hard time following your suggestion. Thank you