Requirement:

I had to fulfill a requirement wherein my client wanted Multi select refinement items in the search results page.

By default SharePoint has single selection enabled like below:

singlerefiner

Solution:

When the requirement was given, my first though was to write a JQuery script to enumerate all the refiners & construct my own checkbox list. THAT IS A BIG MISTAKE. When it comes to SharePoint we are not sure what comes OOB, so it is always better to google\bing it first.

Step 1:

Edit the page & then click the Edit web part link of the Refiners web part

singlerefiner_edit

Step 2:

Now the web part properties window, click the Choose Refiners buttons.

webpart_properties

Here choose the refiner for which Multi-Select is needed and change the “Display Template” as shown below “Multi-Select Refinement Item” then click OK

multiwebpart

Step 3:

Click OK & then save- > publish the page

Final output:

singlerefiner –> final

Note:

All the refinement related styles that you see above are custom written & SP doesn’t render them like this.

Additional stuff:

The working code (except the applying the refiners part) is listed below, so that at least no other person will waste their time on this. 🙂



$(document).ready(function () {

 

ExecuteOrDelayUntilScriptLoaded(CollapseAllRefinerSections, “ajaxtoolkit.js”); ExecuteOrDelayUntilScriptLoaded(EnumerateAllRefinerNames, “sp.datetimeutil.js”);

 

});

 

function CollapseAllRefinerSections() {

 

$(“A.ms-ref-refinername DIV.ms-ref-uparrow”).each(function () {

 

$(this).parent().click(); });

 

}

 

function EnumerateAllRefinerNames() {

 

$(“div.ms-ref-refiner DIV.ms-ref-unsel-longList”).each(function () {

 

var refHeadingName = $(this).parents(“.ms-ref-refiner”).children().find(“A.ms-ref-refinername”).text().trim();

 

var newHTML = “”;

 

$(this).children().find(“.ms-ref-name”).each(function () {

 

var refName = $(this).text().trim();

 

var refCount = $(this).next().text().trim();

 

newHTML += ” + ‘ ‘ + ” + refName + ‘ ‘ + refCount + ” + ‘

‘; });

//Buttons newHTML += ” + ‘‘ + ‘APPLY ‘ + ‘‘ + ‘CLEAR‘ + ”;

 

newHTML += “”;

 

$(this).parent().append(newHTML);

 

//Removes all existing selected\unselected\unlisted

 

//$(this).parent().html(newHTML); });

 

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: