Developer forum

Forum » Ecommerce - Standard features » [Filters] - Order

[Filters] - Order

Ricardo Pedra
Reply

Hi guys,

How can I order by "Facets" in the new index?

I can't find any option in the backoffice. 

 

Best,

Ricardo Pereira

 


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Ricardo,

I'm not sure I understand what you're trying to do.

Are you trying to sort the list of facet options for your facets or are you trying to sort the result set?

- Jeppe

 
Ricardo Pereira
Reply

Hi Jeppe,

I'm trying to sort the list of facet options (GetLoop("Facets")) in the backend.
 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

The facet options for field facets are sorted alphabetically by default. There's no option to change the sorting for this facet type. You can use a Razor template to change the order in which they are rendered by doing something like this.

// Assume 'facet' is a LoopItem from the 'GetLoop("Facets")' loop
// This code will reverse the sort order of the facets, but you can create your own lambda instead
var facetOptionsOrdered = facet.GetLoop("FacetOptions").OrderByDescending(optionLoopItem => optionLoopItem.GetString("FacetOption.Label"));
foreach (LoopItem facetOption in facetOptionsOrdered)
{
    // Render facet options here
}

- Jeppe

 
Ricardo Pereira
Reply

Thank you Jeppe.
It would be interesting if we could sort the filters in backend "defined by user".

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Maybe I misunderstood you.

Are you talking about the order of the facets or the order of the facet options?

Consider two facets: Color and Size. For Color, there are three values: Red, Green, Blue. For Size, there are two options: Small, Large.

In this example, do you want to specify how Color and Size are sorted or do you want to specify how "Red, Green, Blue" and "Small, Large" are sorted?

 
Ricardo Pereira
Reply

I want sort the color and size.

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

The sort order of these elements are exactly the same as in the UI.

You can either add the facets in the order you want to display them at design time, or you can use the Razor template to decide the order. There is another option if you don't want to use the Razor template to control this. You can edit the order directly in the configuration file. That file is located inside your repository folder here: /Files/System/Repositories/<RepositoryName>/<FacetGroupName>.facets. Simply change the order of the facets to the order you want.

Votes for this answer: 1
 
Ricardo Pereira
Reply

Changing the file solves the problem, but would be good if we could change the sort of the facets in the backend.

Thank you Jeppe

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

We will be doing an overhaul of the UI at some point in the near future. I'll keep it in mind.

 

You must be logged in to post in the forum