Thanks to the good people on here I am so close to what I want my table to do. So thanks guys.
2 quick questions:
1) On the drop down list box I am using to search my table is there a value I can put for ALL (show all records)?
2) In the event that there are no records to show is there a bit of code to add "No records to show"?
Once again guys thanks for all your help.
Dear Yoav
Tried the 2nd one above. Added a "noRecordsMessage" text box (hidden) and code now looks like:
=========================================================
import wixData from 'wix-data';
//For full API documentation, including code examples visit http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: import wixData from 'wix-data';
});
export function searchButton_onClick(event) {
wixData.query('TopSanta')
.eq("avail", "Y")
.contains('airport', $w('#selection1').value)
.contains('type', $w('#selection2').value)
.contains('season', $w('#selection3').value)
.ascending("airport", "date", "duration")
.limit(100)
.find()
.then(res => {
if (res.items.length === 0) {
$w('#noRecordsMessage').show();
$w('#table1').hide();
}
else {
$w('#noRecordsMessage').hide();
$w('#table1').expand();
$w('#table1').show();
$w('#table1').rows = res.items;
}
})
=========================================================
However, on the very last line it says "missing semicolon" and "unexpected token". Can you advise what it should be at the end?
One the first one from above I was unsure where I add the ALL "-" code. If you can say where that would be great.
Cheers for everything. I hope all's going well with the BETA.
:-)
Hay Hugh,
You can do both things with a little of code.
For the first, just add another value to the list - with label ALL and some value placeholder, for instance '-'
Then in the onChange event do an if, like -
export function dropdown1_onChange(event) { let value = $w('#dropdown1').value; if (value === '-') // run query without filter else // run query with filter }
For the second, just use a check on number of items returned and show an element with the "No records to show" message. You can also hide the table / gallery at the same time.
This will look like
wixData.query('collection') ... .find() .then(res => { if (res.items.length === 0) { $w('#noRecordsMessage').show(); $w('#table1').hide(); } else { $w('#noRecordsMessage').hide(); $w('#table1').show(); $w('#table1').rows = res.items; } })