You can sort facet options by using transformFacets (more info on our Github).
transformFacets takes in and returns an array of the facet options, so you can write your own custom sorting logic in Javascript. Some examples:
transformFacets: facets => {
return facets.map(facet => {
//Sort address.region by ascending
if (facet.fieldId === 'address.region') {
facet.options.sort((a, b) => (a.value > b.value) ? 1 : -1)
}
//Sort languages by descending
if (facet.fieldId === 'languages') {
facet.options.sort((a, b) => (a.value > b.value) ? -1 : 1);
}
//Pin New York to the top of address.city when sorted by descending
if (facet.fieldId === 'address.city') {
topPinIndex = facet.options.map(option => option.value).indexOf('New York');
topPin = facet.options.splice(topPinIndex, 1);
facet.options.sort((a, b) => (a.value > b.value) ? -1 : 1);
facet.options.splice(0, 0, topPin[0]);
}
return facet;
});
}
If you are using the Answers UI SDK, you can pass transformFacets as part of the parameters of ANSWERS.addComponent('Facets', {})
If you are using the Code Editor, you can do a jambo override for this file and replace lines 11-13 with your transformFacets. It’s an .hbs file, but you can put JavaScript there.
Best,
Bowen