Filtering a SharePoint 2013 list using user provided values

Let’s say we have a InfoPath form containing a multiple selection list box.
Because we need to keep track of every selection made in this list box, we choose to “merge” the data from this list box into a column when it is published to SharePoint.  This results in a column in the form library containing entries with concatenated strings (e.g. “Item 1 Item 3…Item 6”).

It isn’t unreasonable to need to find items in this list where a certain item is selected.  Unfortunately how this is done isn’t as straightforward as one might think as there are several pitfalls:

  • Were this a regular text column you could create a view that grouped items based on the column.  However, the merged column created by InfoPath is not sortable or filterable.
  • You could create a view that filtered all entries that contained the item text that you are looking for.  But you’d have to create a new view for each item in the list.
  • URL filtering at the URL level (1) doesn’t work either: this would only show results where the text you are looking for is the ONLY item selected.  For example, if Items 1, 3, and 5 were selected in on entry that entry would not show up since the URL filter is looking for the text “Item 1” and only that text.
  • You could tell users to use the search functionality on the list. Though this works it may also present some false results if your entries contain similar data across multiple columns.

So what do we do?  There is a solution, and it involves Web Part filters, which allow users to filter data on a web part based on their input.  To set this up involves a number of steps, so let’s go through them.

  1. Create a new (or modify an existing) view in the relevant list.  NOTE: This method only works for standard list views.  It will not work for calendar or Gantt views (if you know of a way to get this to work, please speak up).
  2. In the “Filter” section of the edit view page, add a filter for the appropriate column and set the text for the filter to be
    {<variable>}

    where <variable> is a variable name of your choosing.  This text will be substituted for the text that the user provides later on.

  3. Save the view, then navigate to it (if applicable).  Click on the gear on the top right hand side of the page (next to your name and before the help button), then select “Edit Page.”
  4. You will be placed into an edit view with a one column SharePoint page design.  Click on the “Add a Web Part” link.
  5. In the “Categories” section of the resultant ribbon, select the “Filters” folder.  This will present you with a list of Web Parts that can be used as filters for your page.  Select a filter of your choice, then click the “Add” button.
  6. Your selected filter will be added to the page.  Some web parts need to be configured; if this is the case, configure it now (click on the web part, then the “Web Part” tab on the ribbon, “Web Part Properties”).
  7. Save the changes to your page (“Page” tab in ribbon).
  8. Determine the HTML name for the form field that you just added by referring to the HTML code for the page.  For most of the filters this is the text field that contains the text that will be searched for when the filtering is performed.
  9. Open the site in SharePoint Designer.  Using the “All Files” folder, navigate to the list that you are editing and look in the “Forms” folder for the view that you are editing.  Open the file.
  10. Look for a XML tag block named <ParameterBindings>.  It should contain several <ParameterBinding> tags.  Add another:
    <ParameterBinding Name="<your parametername>" Location="Postback;Connection;Form(<fieldname>);QueryString(<variable>)" />

    <ParameterBinding> is the name that the SharePoint filter is expecting to pass it’s selected value to; <variable> is the name you chose earlier.  These can be same.  <fieldname>is the name of the field you found in step 8 (3), (4).

  11. Save the page.
  12. Edit the page as you did in step 3.
  13. Select the filter web part.  Click on the drop down menu on the top right, then select “Connections > Send Filter Values to > .”  You will be presented with a web page dialog – some web browsers may try to hide this pop up, so you may need to disable pop up blocking on your browser for your SharePoint site if you haven’t already.
  14. “Get Parameters” from should be selected by default as the “Connection Type;” if it is not select it.  Click “Configure.”
  15. The next page/tab should have the variable name that you created in step 10.  Again, if it is not select it.  Click “Finish.”
  16. Congratulations, you’ve set up a linked filter!  Try it out to see if there are any issues that need fixing: if you enter a value in the filter text box and hit enter, the web part below should update with the filtered results.

References

  1. https://msdn.microsoft.com/en-us/library/cc751316.aspx
  2. https://support.office.com/en-us/article/Work-with-filter-Web-Parts-4d052e5d-c5e9-437b-aa36-ae50b6c2678f
  3. https://msdn.microsoft.com/en-us/library/office/ff630170.aspx
  4. http://www.sharemuch.com/2014/03/13/how-to-do-advanced-sharepoint-list-view-filtering-with-query-string-paramters/

Leave a Reply