Today I had the same problem as described in the following forum post:
http://social.technet.microsoft.com/Forums/en-US/260afea2-45e4-41f6-879d-bff7a7ac7e8f/using-calculated-columns-in-the-search-refinement-panel
So first I looked into how the refinement panel works.
There is a Display template called Vertical (Control_Refinement.html and Control_Refinement.js) that creates the refinement panels
Then when I ran the Vertical javascript in my debugger I figured out that the Filter_Default.js controls the format of all the refinement panels.
Ok, so I do’t want to modify any out of the box files so I created a copy of the Filter_default.js. All I now need to do is reference it … Hmm, where is that done then?
I exported the refinement web part and within the SelectedRefinementControlsJson property it is possible to specify the filter script that should be used.
<webParts>
<webPart xmlns=”http://schemas.microsoft.com/WebPart/v3″>
<metaData>
<type name=”Microsoft.Office.Server.Search.WebControls.RefinementScriptWebPart, Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>…
<property name=”SelectedRefinementControlsJson” type=”string”> ….. “displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”
….
<property name=”Direction” type=”direction”>NotSet</property>
</properties>
</data>
</webPart>
</webParts>
Ok, so that is easy… Export, change the display template for the affected filter and import the web part again ( isn’t there a property available in the interface). Yes of course there is. I just missed it the first time around. Edit the web part Then select Choose Refiners … and select the Display template
So all I now have to do is download the Filter_default and fix it and upload it to my display templates.Only about 450 lines of JavaScript in there.
Near line 232 you will find the following code
for(var i in listData)
{
listData[i].RefinementTokens = [listData[i].RefinementToken];
listData[i].RefinementTokenWrappedValues = [Srch.RefinementUtil.stringValueToEqualsToken(listData[i].RefinementValue)];
if(ctx.RefinementControl.propertyName == “MediaDuration”)
{
Srch.U.modifyMediaDurationRefinementName(listData[i]);
}
}
Add the following two lines:
listData[i].RefinementName=listData[i].RefinementName.replace(“string;#”,””);
listData[i].RefinementValue=listData[i].RefinementValue.replace(“string;#”,””);
giving the following result:
for(var i in listData)
{
listData[i].RefinementName=listData[i].RefinementName.replace(“string;#”,””);
listData[i].RefinementValue=listData[i].RefinementValue.replace(“string;#”,””);
listData[i].RefinementTokens = [listData[i].RefinementToken];
listData[i].RefinementTokenWrappedValues = [Srch.RefinementUtil.stringValueToEqualsToken(listData[i].RefinementValue)];
if(ctx.RefinementControl.propertyName == “MediaDuration”)
{
Srch.U.modifyMediaDurationRefinementName(listData[i]);
}
}
And now your refinement panel looks as expected without the string;#
Hello, thank you for your interesting blog. I was wondering, related to the refinement panel, if you should have a solution to enable the MUI multilanguage of the refinement values. Apparently, out of the box, this is not possible in SP2013. I’ve found a custom webpart somewhere: http://ventigrate.codeplex.com/wikipage?title=MUI%20Search%20Refinement%20Panel&referringTitle=Home%22 but it doesn’t seem to work in 2013. Any tips or hints ?
Hi Geert,
Thank you for your interesting question. I must say that I have never had to use the refinement panel in a multi language environment yet.
The refinement panel is made up of Display Templates so multi language support should be possible (http://radutut.wordpress.com/2013/02/10/localizing-display-templates-in-sharepoint-2013/)
Are you comfortable with developing display templates?
Pieter
Hey Pieter,
thanks for your reply.
I’ve adjusted a couple of display templates and am familiar with developing with the client-side OM so i guess this must be do-able 🙂 I’ll give it a shot !
Hi Geert,
Good luck. Let me know if you get it to work.
Pieter,
it’s been a while but in the meantime i was able to construct a solution via javascript:
http://blog.everydayslaughter.com/2015/07/mui-refinements-panel-in-sharepoint-2013/
Hi Pieter
I believe there is a small mistake in your solution. The second line should be:
listData[i].RefinementValue=listData[i].RefinementValue.replace(“string;#”,””);
Hi Adriaan,
Yes, you are right. I have now corrected the typo.
Thanks!
Pieter
Hi Pieter. This is a great post! I have a custom search page created that uses refiners of calculated columns for the month and the year. I used your fix above and it converted the refiner for the Month column correctly but the string;# is still in front of the Year column. Any ideas?
Hi Heather,
The easiest way to check what is going wrong:
1. load the page in IE
2. Run in Debug mode (F12)
3. find the “listData[i].RefinementName=listData[i].RefinementName” lines in your javascript.
4. set a break point on the above line
5. Check what listData[i].RefinementName is set to before and after the above line.
I hope this helps.
Pieter
Update: I actually found the problem. When choosing the refiner, one of the options is multi-value refinement item or refinement item. I didn’t notice that refinement item was listed as an option 2 times for some reason. For the month, I had the 2nd one chose but for the year, I had the first one chosen. When I selected the 2nd (refinement item) for the year, it corrected the formatting and removed String;# from the fields.
Great! I am glad that you solved the issue.
Pieter I wanted to do this based off the multi-value refinement item template. Any suggestions?
Sorry for the delay in responding. Did you get your issue resolved. There shouldn’t be too much of a difference for multiple or single value refinements. in both cases the string;# can be cleaned up in the same/similar way.
Hi Pieter,
I did the same and its working fine in Firefox. But it is not working in IE. Any suggestion?
Could you stick your browser debugger on and set a breakpoint in the display template on the for(var i in listData) line? That should give you an idea of what is going wrong.
Please let me know if this helps or not.
Hi, thanks for this. It solved my problem but I had to tweak the template and input the extra code using single quotes only as below:
listData[i].RefinementName=listData[i].RefinementName.replace(‘string;#’,”);
listData[i].RefinementValue=listData[i].RefinementValue.replace(‘string;#’,”);
Again thanks for taking the time to post this fix.