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() }); })}
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.
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`).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; } ); })
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);
})
}