Developer forum

Forum » PIM » Ordering of facets

Ordering of facets

Stephen Jackson
Reply

I have a facet where I would like the values to be in a specific order in the page. Currently they are just printed in the order we get them ffrom the data model.  Looking at the dropdown select box values that this facet is based on, you can select in which order the drop-down values are, but this does not reflect the ordering of the facet values. How do you set the facet value ordering?


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Stephen,

 

Currently you cannot choose that in the UI, but you can do that int he templates. Assuming you are using Swift, search for the instances of facet.Options and based on facet, you can use a simple LINQ expression to sort by Label, Value or Amount of results.

For example:

  • foreach (FacetOptionViewModel option in facet.Options.OrderBy(f => f.Label))
  • foreach (FacetOptionViewModel option in facet.Options.OrderBy(f => f.Value))
  • foreach (FacetOptionViewModel option in facet.Options.OrderBy(f => f.Count))
  • foreach (FacetOptionViewModel option in facet.Options.OrderByDescending(f => f.Label))
  • foreach (FacetOptionViewModel option in facet.Options.OrderByDescending(f => f.Value))
  • foreach (FacetOptionViewModel option in facet.Options.OrderByDescending(f => f.Count))

 

Ideally you'd make this decision per facet, so you could so something like this instead:

  • var sortedFacetOptions = facet.Name == "My special facet" ? facet.Options.OrderBy(f => f.Value) : facet.Options;
    foreach (FacetOptionViewModel option in sortedFacetOptions)

 

There are a number of ways to go about this, but ultimately, I believe the 6 variations of Label, Value and Count, Asc vs Desc, should get you all possibilities you may need.

 

Best Regards,

Nuno Aguiar

 

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum