I wanted to have buttons that filter onClick and I managed to create these Sort buttons.
// *******************************
// ******SORT FILTER BUTTONS******
// *******************************
export function OldNewButton_onClick(event) {
console.log("Sorted Videos Oldest To New");
$w("#videos").setSort( wixData.sort()
.ascending("created")
);
}
export function NewOldButton_onClick(event) {
console.log("Sorted Videos Newest To Old");
$w("#videos").setSort( wixData.sort()
.descending("created")
);
}
export function ZAButton_onClick(event) {
console.log("Sorted Videos Z To A");
$w("#videos").setSort( wixData.sort()
.descending("title")
);
}
export function AZButton_onClick(event) {
console.log("Sorted Videos A To Z");
$w("#videos").setSort( wixData.sort()
.ascending("title")
);
}
They work great as long as there is no existing filter or query.
I want the sort to also work on searched results and filtered results.
I have a bunch of filter buttons with this code.
// ... filter videos to TAG
export function TAGButton_onClick(event) {
console.log("filtering videos to TAG");
wixData.query('Videos')
.contains('tags', 'TAG')
.descending('created')
.find()
.then(res => {
console.log("Dataset is now filtered to TAG");
$w('#resultsTable').rows = res.items;
})
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
}
When I click one of these buttons it filters to the tag but my Sort (A-Z, ascending…) buttons have no effect. Same if there clicked after a search query.
How can I get the sort buttons to connect to every filter/query and the default dataset?