Sort a dataset by a second-level property

I have a collection with a field referenced one-to-one to another collection. I’d like to sort my dataset, connected to this collection, by a second level property of this reference.

Pretend the situation — I have a collection with condos, a collection with amenities types and a separate collection ‘Condos-Amenities’, where I create amenities descriptions for condos:

| condo (reference to ‘Condos’) | amenity (reference to ‘Amenities’ | description (text) |

in ‘Amenities’ I have a field ‘priority’ and I’d like to have a dataset, filtered by current condo item (no problem here) and sorted by amenity priority.

I don’t see referenced object fields in the sort, as I see these fields when I connect interface elements to this dataset. Only fields from this particular collection. I’m trying to do this in code but it doesn’t work:

$w(‘#datasetCondoAmenities’).onReady(() => {
let condosAmenitiesSort = wixData.sort().ascending(‘amenity.priority’);
$w(‘#datasetCondoAmenities’).setSort(condosAmenitiesSort);
})

Thank you for your help.

1 Like