0

I have a start page in SharePoint 2013 (on premises) where I use search results (without search box) and a refiner panel to display a long list of items found at multiple sites. In the refiner panel I can filter the search results that are found when the page is loaded.

By default I get all results, because there is no refinement done during page load. But 95% of the users only would like to see "Active" items, not "All" items which is default.

Can I preset the refiner value to "Active"? Then I would have the relevant results displayed at once, and if someone would like to see other items they would be able to change this using the refinement panel as usual. How can this be achieved?

2

Yes you can do it by using the addrefinementfilter method. Add a script editor webpart at the bottom of page after the Content search/search results webpart.

Then add the below code:

 // Get the refiner control - the ID needs to be retrieved from your control
var refiner = $getClientControl(document.getElementById("ID of the search refiner"))

refiner.addRefinementFilter('FileType', 'html')
{"k":"test","r":[{"n":"FileType","t":["html"],"o":"and","k":false,"m":null}]}

Add this code on page load using document.ready or similar javascript/jquery method.

In the above example, my refinement filter is FileType and the value is "test". So your code could be:

refiner.addRefinementFilter('RefinableString00', 'html')
    {"k":"Active","r":[{"n":"FileType","t":["html"],"o":"and","k":false,"m":null}]}

Reference - The Search Refiner Control Methods Explained

  • Thank you! I have a question though, since the syntax is rather complicated. My items are not files so no file types like 'html' are involved. My items are just items found in different lists. I would like to filter on a value found in the list columns. It is a list column "Item Status" that could have the value "Active" and this is in the end mapped to a RefinableString used in the refiner panel. What should I specify instead of FileType and 'html'? – Gunilla Oct 20 '16 at 6:23
  • ok you can also use it like - refiner.addRefinementFilter('RefinableString', 'Active'); – Gautam Sheth Oct 20 '16 at 6:28
  • Great! What would be the easiest way to find out the id that I should write in the getElementById method? – Gunilla Oct 20 '16 at 7:23
  • Does the id look something like this: – Gunilla Oct 20 '16 at 9:09
  • "\"\u01c2\u01c2416374697665\"" – Gunilla Oct 20 '16 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.