I have a table “Table2” that is on a dynamic page, and filtered by the title field to show only items related to the dynamic page. The dataset connected to it is called “Albums”.
What I would like to do is hide the strip which the table is in whenever the filtered results are empty.
I have tried the below code, and a lot of other variants, but it either results in error or nothing happens
wixData.query(“table2”)
.find()
.then((results) => {
console.log(results.items.length); // check the length of results in the console
if (results.items.length === 0) {
// Table2 is empty
$w(“#StripDiscography”).collapse();
$w(“#StripDiscography”).hide();
} else {
// Table2 has data
$w(“#StripDiscography”).expand();
}
});
I would appreciate your help as I can’t for the life of me get it to work
As per the link you shared, a table is a table for dispaying data, which is exactly what I’m using and its ID is #table2
My collection’s name is Artists
Yes, it was clear for me that you are using a table, but the code you have presented, won’t work on a table. This is why i wanted to make clear, that you really are talking about a TABLE.
Yes on your pic we can see the wix-element (TABLE), which either can be connected to a DATASET (and the dataset itself will be connected to your DATABASE), or it can be connected directly to databse (using some code).
In your case you already are using a DATASET.
You can try to manipulate your table with the following code…
Paste that code onto your related page and open it in PREVIEW-MODE.
Take a look onto console. What do you get as → RESULT <— when you do changes on your table ???
When running the code you provided, whenever the table is empty, it results in the following error: Error: Cannot read properties of undefined (reading ‘map’).
When it is run when the table is populated, it shows the array
Can you show the 2x different original screenshots (good and bad data) ?
Also do open the (OBJECT / ARRAY).
I do not have all these informations in front of my eyes …
Anyway → we already created two different states ! ( STATUS ) → BAD & GOOD
One works, when table has items and the second state is an ERROR-STATE.
Your wish was…
Collapse Strip if table is empty
That means → if you get the error → normaly your Column-Strip should close right?
And if you get some results → your Column-Strip should open again showing your table, what also makes sense, right?
There are now surely several different options of how to manage this problem.