I am using Database to generate a list of items.
When I ‘Preview’ the items on my site, they appear either in reverse alphabetical order or in any other random order.
I have then tried a simple Database with six items in the first column, these items being: the letters A, B, C, D, E, F. I have then generated a page and when I preview they are in reverse alphabetical order or in any other random order.
I cannot remedy the issue.
HELP !!!
Someone has suggested ‘I could always code it’. I am not sure what this means…?
Hi Ian,
when using wix-data to query this collection, please also use sort. in different situation you may also want to display the data sorted differently
Shlomi
Hello, I solved the problem by placing the data in alphabetical order, I then created an enumerated column, and I passed the following code as an example:
function loadBAIRROS() {
wixData.query(‘BAIRROS’)
.ascending(“ordem”)
.limit(60)
.find()
.then(res => {
let options = [{
“value”: ‘’,
“label”: ‘Selecione um Bairro’
}];
options.push(…res.items.map(bairro => {
return {
“value”: bairro.bairros,
“label”: bairro.bairros
};
}));
$w(‘#iBairro’).options = options;
});
}
If you are simply using a table, repeater or gallery etc to show info from a dataset on your page, then you can simply set the filter for the dataset’s own field that you want to organise it all by.
https://support.wix.com/en/article/about-filtering-and-sorting-database-content-displayed-in-page-elements#sorting-your-dataset
The default sort order is the date the item was added, with newer items appearing first. This date appears in the “Date_Created” system field. When you add a new sort, the default sort disappears.
If we continue our example from the above link, we want the recipes to be listed alphabetically by recipe name. So our field would be “Recipe,” and our order would be “A-Z.” The image on the link shows how this looks.
If it is search on a dataset that is shown in a table or a repeater, then you can just use simple code like this.
import wixData from 'wix-data';
$w.onReady(function () {
export function button_click(event) {
let value = $w("#input").value;
let filter = wixData.filter();
$w("#dataset").setFilter(
filter.eq("type", value)
);
}