Two tables, filtered from reference table...but how?

I have a master table ( TABLE1 ) that shows a list of products (vitamins). The table contains TITLE, COST, and so on. TABLE1 also contains Category1, Category2, Category3 to list multiple categories the vitamins products can be in. Category are REFERENCE fields from another database that lists only categories available.

When I try to do this:

export function table2_cellSelect(event, $w) {
//This changes the TABLE1 products from the category listed in table2
let cellData = event.cellData;
$w(“#dataset1”).setFilter(wixData.filter()
.contains(“Category1”, cellData));
//test line from text element to show data within cellData variable
$w(“#text21”).text=cellData
//test line
}

The table clears out, but the text21 data shows the correct “string” of text of the correct category, (such as Brain Health, Adrenal Support, etc)

Do I have to use a data HOOK to load the reference data before the click on the celldata?
I’m just trying to load the contents of the table to that particular category of vitamins. Easier way to do it?

Hi,
I think you can achieve that automatically by using one dataset for the master table, and another dataset for the details table (table1 and table 2). Then, you can filter the details dataset by the master dataset.
Check out this article: CMS: About Displaying Content from Multiple Database Collections Using Reference Fields | Help Center | Wix.com
Specifically the “Table Showing Related Information (Master-Detail)” section.

Ok, I’ve got it working, however when adding multiple filters they only set as AND (they are all active). (Vitamins for Vision AND Bone Health AND Prostate). There is no way, without coding it, for you to set the filters for the master dataset as OR (Vitamins for Vision OR Bone Health OR Prostate).

Is there a way to filter a master dataset via code so I can use OR? Below works, but only if I go in and set in the database the category field as just text, NOT REFERENCED.

export function table2_cellSelect(event, $w) {
//This changes the TABLE1 products from the category listed in table2
let cellData2 = event.cellData;
$w(“#dataset1”).setFilter(wixData.filter()
.contains(“category”, cellData2));

UPDATE: I’ve written the code below that uses rowSelect to get the ID from the table that is clickable. If I use the _id (its the very long A239487324-23489723-11ve4F id CODE) of the REFERENCED dataset, then I can filter it that way. So, a visitor to the website sees a list of CATEGORIES of vitamins (Eye Health, Brain Health) on the left side. This is table2. They click on a Category (Eye Health), and then this code reads the row data into rowData. Since Wix can’t currently set the filter on a dataset field that is defined as reference (not sure why???), this comes in a close second as it uses the _id of the table from the reference dataset.
Hacked…yes. But works. Make sure the table is set to select ROW and not CELL. I still can not do multiple filters set as OR, but thinking on how to do this as a QUERY.

Example:

export function table2_rowSelect(event, $w) {

let rowData = event.rowData; // gets row DATA when you click on the table that has the REFERENCED
dataset list. specifically wanting _id, to use as FILTER variable. see next

$w(“#dataset1”).setFilter(wixData.filter() //uses _id, supplement name as CODE, to filter table
.contains(“category”, rowData._id)); 12