Content Manager data sort

I have been trying out using the DevMode on Wix to format my content manager (all) page so that I can have tags associated with the events I am posting. I have managed to get the tags to work but in doing so I can no longer use the filter/sort option in the dataset settings to get the events to display in chronological order.

Please can someone take a look at my code and tell me what I can try to amend this issue?

Thanks in advanced!

Current code i’m using which allows me to use the tags:

import wixData from ‘wix-data’ ;

const collectionName = ‘Courses’ ;
const fieldToFilterByInCollection = ‘section’ ;

$w.onReady( function () {

setRepeatedItemsInRepeater(); 
loadDataToRepeater(); 

$w( '#tags' ).onChange((event) => { 

const selectedTags = $w( ‘#tags’ ).value;
loadDataToRepeater(selectedTags);
})
});

function loadDataToRepeater(selectedCategories = ) {

let dataQuery = wixData.query(collectionName);

if (selectedCategories.length > 0 ) {
dataQuery = dataQuery.hasAll(fieldToFilterByInCollection, selectedCategories);
}

dataQuery 
    .find() 
    .then(results => { 

const itemsReadyForRepeater = results.items;
$w( ‘#repeater1’ ).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0

if (isRepeaterEmpty) {
$w( ‘#noResultsFound’ ).show();
} else {
$w( ‘#noResultsFound’ ).hide();
}
})
}

function setRepeatedItemsInRepeater() {

$w( '#repeater1' ).onItemReady(($item, itemData) => { 
    $item( '#text6' ).text =itemData.title; 
    $item( '#text6' ).src = itemData.image; 
    $item( '#image1' ).tooltip = itemData.title; 
    $item( '#text2' ).text =  '$'  + itemData.productPrice; 
    $item( '#button2' ).text =itemData.tags; 

})

Hi there @emalouiseballx :raised_hand_with_fingers_splayed:

I can’t see your sorting function? Maybe share screenshots of the layout (repeater), and explain more on how you intend to filter them or sort them based what?

Here’s a tutorial video showing you how to handle multiple filters with wixData .

When you’re done refining your query, add the sort to the query before calling it.

dataQuery.ascending('dateOrder').find()

Don’t forget to replace “dateOrder” with the actual field ID.

Please let me know how it goes.
Ahmad

Hi Ahmad,

Thanks for your reply. I am new to using code do I need to add code to add a filter too? Below is what it currently looks like but Id like the courses to show in date order…

@emalouiseballx I’m really confused now, you’re using wixData in your code, and you’re showing me a screenshot of dataset, yes you need to sort the query each time you call it. I’ll update my answer to show you how.

Thanks for this, so where within the code do I need to add this?

@emalouiseballx Right before the find( ) ;