Sorting Query problem PLEASSSSS HELP

I made website where people book rooms for wedding. .I can delete rooms and add them and it works.
Upper part occupied rooms sort via dataset.
Down part is taken from query and i have no idea how to sort it. I tried via collection, dataset, add descending to quey. No way. I need to sort it via localization.
https://misiewicz3.wixsite.com/mysite/kopia-pokoje
misiewicz@hpworldwide.pl
info

My code is like this.

function getEmptyRooms() {
// Get list of occupied rooms (we return a Promise so that the calling function can
// process the results
return getOccupiedRooms()
.then((occupiedRoomList) => {
let emptyRoomQuery = wixData.query(“pokoje”);
// loop through occupied rooms creating a list of queries to exclude occupied rooms
for ( let i = 0 ; i < occupiedRoomList.length; i++) {
// Get a record to exclude
let occupiedRoomRecord = occupiedRoomList[i];
let exclusionQuery = wixData.query(“pokoje”)
// .descending(“lokalizacja”)
// .ascending(“title”)
.eq(“_id”, occupiedRoomRecord.pokoj);
emptyRoomQuery = emptyRoomQuery.not(exclusionQuery);
}
// We have built our Empty Room Query - now execute it
return emptyRoomQuery.find();
})
.then((results) => {
return Promise.resolve(results.items);
});
}
let user = wixUsers.currentUser;
let userId = user.id;

function getOccupiedRooms() {

return wixData.query(“zakwaterowanie”)
// .ascending(“lokalizacja”)
// .descending(“pokoj.title”)
.eq(“_owner”, userId)
.isNotEmpty(“_owner”)
.find()
.then((result) => {
// Return a promise with the array of occupied rooms
return Promise.resolve(result.items);

      }) 

}

function pobierzwolnepokoje(){
getEmptyRooms()

.then((emptyRoomsList) => { 

// console.log(“zaczynam repeater 3”);

   $w("#repeater4").data = emptyRoomsList; // Add this 

// console.log(emptyRoomsList);
$w(“#repeater4”).forEachItem( ($item, itemData, index) => {
$item(#text84).text = itemData.title;
$item(#text86).number = itemData.g2

    $item(`#text87`).number = itemData.dostawkimax; 
    $item(`#text90`).text = itemData.lokalizacja 
    $item(`#text91`).text = itemData.uwagi; 
    $item(`#text94`).text = itemData._id; 
    $item("#gallery4").items = itemData.zdjeciepo; 
   } ); 

})

. catch ( (err) => {
// console.log(err);
});

}

$w.onReady( () => {
pobierzwolnepokoje()
});

export function dodajpokoj_click(event) {
$w(“#dataset2”). new () .then(() => {
// $w.onReady(function () {
//$w(“#dataset1”).onReady( () => {
let $item = $w.at(event.context);
let numer = $item(#text94).text
let lokalizacja = $item(#text90).text
let numerek = $item(#text84).text
// console.log(“teraaaaaaaaaaaaaz”)
// console.log (numer)
// let item = $item(“#dataset1”).getCurrentItem();
// let currentItem = item._id;
// let lokalizacja = item.lokalizacja

    $w("#dataset2").setFieldValue("pokoj", numer); 
    $w("#dataset2").setFieldValue("lokalizacja", lokalizacja); 
    $w("#dataset2").setFieldValue("numer", numerek); 

return $w(“#dataset2”).save()
.then(() => {

$w(“#dataset2”).refresh();
})
.then(() =>
pobierzwolnepokoje()
//console.log(“New item dddddddddddddddddddddddddddddddddd”);
)})

}

export function button61_click(event) {
$w(“#dataset2”).remove()
.then(() => {
$w(“#dataset2”).refresh()
.then(() => {
pobierzwolnepokoje()

    }); 

})}

You would really get an answer more quickly if you just posted the small section of code that you are having problems with and not your whole page code. Is below the section of code you are referring to ?

let user = wixUsers.currentUser;
let userId = user.id ;

function getOccupiedRooms() {
return wixData.query(“zakwaterowanie”)
// .ascending(“lokalizacja”)
// .descending(“pokoj.title”)
.eq(“_owner”, userId)
.isNotEmpty(“_owner”)
.find()
.then((result) => { // Return a promise with the array of occupied rooms return Promise.resolve(result.items);
})
}

i putted everything becasue its connected by funcion. function for displaying free rooms is here. And i want to sort it by lokalizacja which is in text90

function pobierzwolnepokoje(){
getEmptyRooms()
.then((emptyRoomsList) => {
// console.log(“zaczynam repeater 3”);
$w(" #repeater4 “).data = emptyRoomsList; // Add this //
console.log(emptyRoomsList);
$w(” #repeater4 “).forEachItem( ($item, itemData, index) => {
$item([#text84](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text84?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData.title;
$item([#text86](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text86?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).number = itemData.g2
$item([#text87](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text87?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).number = itemData.dostawkimax;
$item([#text90](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text90?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData.lokalizacja
$item([#text91](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text91?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData.uwagi;
$item([#text94](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text94?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData._id;
$item(” #gallery4 ").items = itemData.zdjeciepo; } ); })

try this…

function pobierzwolnepokoje(){
getEmptyRooms()
.then((emptyRoomsList) => {

let sortedList = emptyRoomsList.sort();
$w(" #repeater4 ").data = sortedList ;

$w(" #repeater4 “).forEachItem( ($item, itemData, index) => {
$item([#text84](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text84?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData.title;
$item([#text86](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text86?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).number = itemData.g2
$item([#text87](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text87?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).number = itemData.dostawkimax;
$item([#text90](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text90?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData.lokalizacja
$item([#text91](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text91?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData.uwagi;
$item([#text94](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23text94?dvc=c&experiment_id=wix%2Bcode%5Ee%5E209150830980%5E1t1%3B%3Fh&gclid=EAIaIQobChMI7bae8Jzc3AIVGYfVCh0nWgKzEAAYASAAEgJTmPD_BwE&h=https%3A%2F%2Fwww.wix.com%2Fcode%2Fhome&utm_campaign=179424220%5E47357753009&utm_medium=cpc&utm_source=google%2F%2F%2F%2F%2F%2F%2F/)).text = itemData._id;
$item(” #gallery4 ").items = itemData.zdjeciepo; } ); })

@mikemoynihan99 i wouldnt write here if it was so easy. Its already sorted , datase,database and nothing. Room 21 and 11 doeasnt want to sort. Problem is that its taken from query which compare two datasets. Probably because of this its not sorted like datasets

@ceglarnia
I can not understand your english

sorry i write to quickly and dont check later

  1. I have already sorted datasets, i have also tried with collection
  2. When You look at page there are some items that dont want to sort (pokoj 21, pokoj 11)
  3. I think its because i take data from function that is comparing two queries. I dont know how to sort it. I tried to add .ascending .descending to queries and it does not work as well.

Can you just combine your two results from the queries and then sort something like this…

const combinedList = results1.items.concat(results1.items);

const sortedCombinedList = combinedList.sort();

Console.log(sortedCombinedList);

@mikemoynihan99
Thank You for patience with me. Its problem of beginning coder. Whole day i was looking for solution and i noticed that i was adding .descending to all queries but not final one. I added it to getemptyroom query and it works. Just to know for future where should i add .descendiing in this code You wrote before?
function pobierzwolnepokoje(){
getEmptyRooms()
.then((emptyRoomsList) => {
let sortedList = emptyRoomsList.sort(); //it sorts but where should i add how to sort

thank You again

Chris

@ceglarnia

Two options:

let sortedList = emptyRoomsList.sort(); //this one sorts alphabetically

let sortedList = emptyRoomsList.reverse(); //this one will sorts in reverse order

@mikemoynihan99 but which field i mean. How to write LOkalizacja or Title