Introduction
At some point you probably thought about incorporating glossary functionality as a part of a larger solution, or perhaps you were simply looking for providing a more intuitive way of filtering hundreds of items within a List or Library.
Now there are countless web parts out there that you can either purchase or download from the SharePoint Store free of charge, and they all come with their own set of bells and whistles. However, if you are looking at building one yourself, well look no further.
To accomplish this we will need three major ingredients:
- SharePoint Page (either Wiki or Publishing will work)
- SharePoint List/Library with some content (Files/Items)
- HTML Form Web Part
Let's Implement
In this post I’m using a simple Wiki page, but you can also use a Publishing page as well. We just need a canvas to display our glossary.
I presume you already have a list or library that contains some content which is applicable to this concept. I’m simply using a document library with few documents inside it.
Since the concept of the glossary is to filter content by alphabetical characters, we need to provide our library with an additional column that will contain exactly that, alpha characters. To accomplish this we create a calculated column which will store the first letter from the Title column of the document.
The formula field should be populated like so:
This translates to capturing a first character sub-string from the left side of the string inside the Title field. Please ensure that the "Title" field contains values relevant to the "Name" field for each document.
This is what we have once the column is created and added to the default view of the list/library.
Next we add a List/Library app and HTML Form Web Part to the page. Let’s see what that looks like.
The beauty about HTML Form Web Part is that out-of-box we can write our own HTML code, place it inside the Source Editor, and have it render on the page. By default HTML Form Web Part comes with two HTML controls; Textbox, and a Button. Let’s edit the HTML Form Web Part and see what that looks like inside its Source Editor.
Edit the HTML Form Web Part to open its Tool Pane and click the Source Editor in the Form Content section.
This opens up a text editor containing HTML source of the above mentioned controls (Textbox, Button)
We will modify this code and add our own HTML source which will enable us to pick the alphabetical characters from the drop down menu. Replace the existing piece of HTML inside the Source Editor with the following:
<div onkeydown="javascript:if (event.keyCode == 13) _SFSUBMIT_"> <select name="IndexChar"> <option value="">**Select Letter**</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> <option value="E">E</option> <option value="F">F</option> <option value="G">G</option> <option value="H">H</option> <option value="I">I</option> <option value="J">J</option> <option value="K">K</option> <option value="L">L</option> <option value="M">M</option> <option value="N">N</option> <option value="O">O</option> <option value="P">P</option> <option value="Q">Q</option> <option value="R">R</option> <option value="S">S</option> <option value="T">T</option> <option value="U">U</option> <option value="V">V</option> <option value="W">W</option> <option value="X">X</option> <option value="Y">Y</option> <option value="Z">Z</option> </select> <input type="button" value="Go" onclick="javascript:_SFSUBMIT_"/> <br /> <a href="relative URL of the page with web parts">REFRESH</a> </div>
Click Save on the Text Editor.
Under Appearance section of the web part Tool Pane change the Title of the web part to something friendlier (i.e., Glossary Filter).
Next, while the Tool Pane is still open, click on the drop down web part menu and select Connections | Provide Form Values To | (Name of List/Library).From the Connection Type drop down select “Get Filter Values From”, then click Configure.
New pop-up dialog opens up prompting us to select a field where filter data is going to be consumed from.
From the Consumer Field Name drop down select IndexFilter.
Click Finish, then click OK to save changes to the web part.
Finally save the page and publish if necessary.
Let's Test
We are ready to test. Select the letter from the drop down menu and click GO button. You should see the list/library values filtered according to the letter selection.
You may have noticed an appearance of a REFRESH button as well. It works well with clearing the filter. If you intend on keeping something like this in your solution just remember to update the HTML source with a relative URL of your page.
And there you have it. Now, this concept may appear redundant since you have other, perhaps quicker ways of filtering values within a list or a library. The value here is that you can apply this concept in other potentially larger solutions that may require more intuitive way of filtering data.
how do you reset the filter to show all again?
ReplyDeleteHello,
DeleteThere should be a REFRESH button right below the dropdown (see the last screenshot in the post).
Thanks!
Hi,
ReplyDeleteI followed the instruction but it is not working for me. It shows filter icon besides the column title but result is not filtered. When I click that icon and clear filter then it display filtered records in a list.
Hi Mumtaz,
DeleteI understand you're having some difficulties filtering using the HTML form web part. A couple of things I would double check. First make sure you have copied and pasted the HTML markup correctly, and replace the text inside the href attribute with the correct relative URL of the page where your Web Part is. Second, please double check your connection between the two web parts. That is most likely where the culprit is.
Hope that helps.
Thank you for your help Ismar. Refresh link works fine. But filtering is not working. I checked the connection as well. And I am just using a text box to get filter values from users in HTML form web part.
DeleteHi Mumtaz,
DeleteI just implemented the same solution using the textbox instead of a dropdown menu, and it filters the contents successfully. Did you check the IndexFilter column in your list/library to make sure that the Calculated Value is in fact extracting the first letter of the Title? Sometimes there is confusion between Title and Name columns and Title frequently remains empty if you're using a document library.
Hello Ismar,
DeleteIt worked for me when I selected "Server Render" for list view web part.
Glad it finally worked out. I looked into this and it appears to be a known issue tied specifically to the Tasks list. Here is the support article: https://support.microsoft.com/en-us/kb/2924913
DeleteThanks for providing the feedback!
Hello Sir please can you help me i'm new in sharepoint
ReplyDeletei want to understand how use html in sharepoint a at z
Hello Caporal.
DeleteThere are a few different ways you can inject custom HTML inside SharePoint pages. Can you be more specific with what you're trying to do, or a solution you're working on. Thanks!
Thanks so much, this works great!
ReplyDeleteThe only problem I had was the REFRESH kept getting an error page, but I just changed the href to the page's relative url and it worked a treat.
:)
Glad that you found this helpful, and a good catch on a relative URL.
Delete