Move Certain facet values to top of facet list
In our Primo, we need certain resource type facet values (books, e-books, journals, e-journals) to be always on top of the facet list, no matter how high the number of expected results is. In the old UI, this was accomplished by dom manipulation via jQuery.
Since we cannot use jQuery with the new UI anymore, I searched for a way to move up the facets via angularjs.
This is my solution – add the following code to the custom.js file in the js folder of your custom Primo package:
app.component('prmFacetExactAfter', { template: '<span ng-controller="FacetExactAfterCtrl"></span>' }); app.controller('FacetExactAfterCtrl', function ($scope) { var facetGroup = $scope.$parent.$parent.$ctrl.facetGroup; function moveToTop(topFacets) { var topFacetObjects = []; angular.forEach(facetGroup.values, function(facet, index) { if(topFacets.indexOf(facet.value) != -1) { topFacetObjects.push(facet); } }); topFacetObjects.reverse(); topFacetObjects.forEach( function(facet, index) { facetGroup.values.sort(function(x,y){ return x == facet ? -1 : y == facet ? 1 : 0; }); }); } if(facetGroup.name == "rtype") { facetGroup.displayedCount = 8; var topFacets = [ "journals", "printjournals", "books", "printbooks" ]; moveToTop(topFacets); } });
Here the number of displayed resource type facets is set to 8. The top facets are moved to the top and ordered among each other according to the number of expected results.
Of course this controller can also be used for the other facet types.
Best regards
Lars Heuer
University Library, Oldenburg, Germany
3 Replies to “Move Certain facet values to top of facet list”
Leave a Reply
You must be logged in to post a comment.
I found something buggish here when clicking the Show More-link: https://www.screencast.com/t/myrHThcx Possible to solve?
Sorry, but I’m not able to reproduce your problem. In our Primo this controller works fine. Without looking at your code it’s hard to find out what’s wrong here.
Kind regards
Lars Heuer
… I just saw that the line
facetGroup.displayedCount = 8;
is outcommented in our code, like that
// facetGroup.displayedCount = 8;
Maybe that could be the solution.