How to order attributes with InstantSearch

I want to filter my attributes Sizes to get :
XXS
XS
S
M
L

Instead of :

Thanks a lot

Hi @wedressfair

In order to help you I will assume your are using InstantSearch.js and the Menu widget.
You can specify a sortBy function to the widget in order to sort your attributes in the way you want (https://community.algolia.com/instantsearch.js/v2/widgets/menu.html#struct-MenuWidgetOptions).

In your use case, the sortBy function should look like this:

sortBy: function (a, b) {
  if (a.name === 'XXS') return -1;
  if (a.name === 'XS' && b.name !== 'XXS') return -1;
  if (a.name === 'S' && b.name !== 'XS' && b.name !== 'XXS') return -1;
  if (a.name === 'M' && !b.name.includes('S')) return -1;
  if (a.name === 'L' && !b.name.includes('S') && b.name !== 'M') return -1;
  if (a.name === 'XL' && !b.name.includes('S') && b.name.includes('X')) return -1;
  return 1;
}

Does it helps?

Yes it help me a lot but I don’t understand why when I click on “XL” it goes at the bottom of the list ?

:point_down:
11

Thanks for your help.