Skip to main content

SharePoint 2013 - Simple Glossary using "HTML Form Web Part"

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:
  1. SharePoint Page (either Wiki or Publishing will work)
  2. SharePoint List/Library with some content (Files/Items)
  3. 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.

Comments

  1. how do you reset the filter to show all again?

    ReplyDelete
    Replies
    1. Hello,
      There should be a REFRESH button right below the dropdown (see the last screenshot in the post).
      Thanks!

      Delete
  2. Hi,
    I 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.

    ReplyDelete
    Replies
    1. Hi Mumtaz,
      I 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.

      Delete
    2. 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.

      Delete
    3. Hi Mumtaz,
      I 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.

      Delete
    4. Hello Ismar,

      It worked for me when I selected "Server Render" for list view web part.

      Delete
    5. 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
      Thanks for providing the feedback!

      Delete
  3. Hello Sir please can you help me i'm new in sharepoint
    i want to understand how use html in sharepoint a at z

    ReplyDelete
    Replies
    1. Hello Caporal.
      There 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!

      Delete
  4. Thanks so much, this works great!
    The 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.

    :)

    ReplyDelete
    Replies
    1. Glad that you found this helpful, and a good catch on a relative URL.

      Delete

Post a Comment

Popular posts from this blog

SharePoint 2013 - Can't access the site externally in Internet Explorer ("Page cannot be displayed")

Synopsis Before we start talking about the problem let's understand the setup here.  We have a SharePoint 2013 intranet site that is also configured for access outside of the corporate network.  Employees use the same URL to visit the site both internally and externally via standard ports (80 and 443). Internal URL: http://sharepoint.domain.com Public URL: https://sharepoint.domain.com The site URL has been added to the Local Intranet zone in Internet Explorer for passing domain credentials. Alternate Access Mappings have been configured in such a way that if a user requests the site over HTTP they are automatically re-directed to HTTPS. Internal URL Zone Public URL for Zone https://sharepoint.domain.com Default https://sharepoint.domain.com http://sharepoint.domain.com Default https://sharepoint.domain.com Web application has been configured to use Kerberos protocol for authenticating incoming c

Remove Orphaned Web Parts - MissingWebPart

At some point you may have encountered an error like this while browsing through the SharePoint Health Analyzer or if you are attempting to test your content database (i.e., Test-SPContentDatabase) prior to mounting it. Message reads something like this: One caveat is that the log message never reveals the Location of the culprit web part.  Luckily we can utilize T-SQL to query the content database and reveal the location of the web part in question.   Query the Content Database To do this fire up the SQL Server Management Studio either locally from your machine or while logged on to the SQL Server back-end of your SharePoint farm, open up the new Query window and enter the following statement: USE < Content_Database_Name > SELECT AllDocs.SiteId,WebId, Webs.Title as 'Web Title', ListId, DirName,LeafName  FROM AllDocs    inner join AllWebParts on Alldocs.Id = AllWebParts.tp_PageUrlID  inner join Webs on Alldocs.WebId = webs.Id  WHERE AllWebParts.tp