3

I have a list and I need to do a search on an item given two fields: topic and community.

Both fields can have more than one item and they're both text field fields from an infopath form:

For example:

Title: "Test Item"

Topic: "Leadership, Marketing"

Community: "Employees, Managers"

I have a dropdown for both those fields and I'm using that to build a url query to return the results

So if a user selected:

Topic: "Marketing"

Community: "Executives"

My query would like this:

&FilterName=Topic1&FilterMultiValue=*Marketing*&FilterName=Community1&FilterMultiValue=*Executives*

  • 1
    So what is your problem? :) – Robert Lindgren Mar 14 '16 at 19:13
  • See similar question at sharepoint.stackexchange.com/questions/72117/… - seems you can't use FilterMultiValue twice – Aziz Kabyshev Mar 14 '16 at 19:25
  • @RobertLindgren sorry, the problem is that the second filter does not work. As the comment above says, I can't use two wild card filters in the url and I can't use multiple FilterMultiValue parameters and there's no way to make an OR condition in the url. However, if a user wanted to find a class that was Topic=Leadership and Community=Managers I can't find a way to return that Test Item using url queries because both would need wildcards. – Batman Mar 14 '16 at 19:56
2

A SharePoint 2010 list view web part can only interpret one wildcard filter from the query string parameters at a time.

If you need to apply multiple wildcard filters to a list view, you can use SharePoint Designer to add parameters to the list view and filter the view by those parameters.

You can then hook into those parameters with web part connections through the browser, using filter web parts or the more basic HTML form web part, or you can have the parameter values come from the query string.

Using SharePoint Designer to Automatically Filter on Query String Parameters

  1. Edit the desired page in SharePoint Designer
  2. Click within the body of a list view on the page to bring up the List View Tools menu in the ribbon
  3. In the Options tab in List View Tools, click the Parameters button to open the "Data View Parameters" dialog
  4. Click the "New Parameter" button
    • Name the parameter something meaningful; I'd go with topicFilter if you're filtering on the topic field, for example
    • Change the Parameter Source to "Query String"
    • Set the Query String Variable to a short value, such as "topic"... this is what you'll be appending to the URL as a query string parameter
    • If you want certain items to be displayed or hidden when no parameter value is provided, put in a default value based on your requirements
    • Click the "OK" button when done
  5. Click within the body of your list view again and this time click the Filter button in the Options tab
  6. Add a new clause
    • Choose the column you want your parameter to filter against in the Field Name column
    • Choose "Contains" from the dropdown in the Comparison column
    • In the Value dropdown, choose your newly created parameter value (which you named in step 4 above)

When you save the page, your list view will now filter on the value provided to the query string. For example, if you added a parameter that uses a query string variable called "topic", you can filter by that parameter by appending ?topic=value to your URL, where value is the value by which you want to filter.

You can repeat the process to add more filtering parameters to filter on multiple fields.

Having the Filters Show All Items By Default

The above technique generally results in the list view showing no items until you provide the required filtering parameters.

If you need the opposite functionality-- with the view showing all items, but allowing you to gradually drill down based on provided filter values-- the only option I'm aware of is to have the default value for the filter be something that will always be true. Unfortunately, that's very much dependent on your column values.

For example, if you can finagle it so that your topic column always contains the topic plus an asterisk character, then a default filter value of * will show all entries.

A potential solution is to copy the column values to another column with some wildcard character appended. This can be accomplished via workflow or event receiver, or even just a calculated column, although that can affect your filtering options since calculated columns can't be indexed. The new column can be hidden from the forms as desired, since you don't want users directly changing its value.

Once you have the new column populated, you can then adjust your list view in SharePoint Designer so that the parameter has that wildcard character as a default value, and then adjust the filtering so that it filters against the new column instead.

  • Would you happen to know of a tutorial that explains how this is done? Also, I don't have the Filter Webparts in my 2010 Standard site, is tehre any way this could work with url parameters? – Batman Mar 14 '16 at 19:49
  • 1
    Without the Filter web parts, the HTML Form web part will be your friend. It's a little uglier at first, but like the ugly duckling it can grow up to be something beautiful (you can modify its HTML directly to make it look how you want, unlike with the filter web parts). – Thriggle Mar 14 '16 at 19:56
  • 1
    If you set up the parameters to accept the query string values in SharePoint Designer, the CEWP will be fine. The HTML form web part would only really be useful if you wanted to use web part connections to connect your filter controls to the list view. – Thriggle Mar 15 '16 at 13:45
  • 1
    @batman I've updated the answer with an approach you can take, although it's kind of hokey and hacky. – Thriggle Mar 15 '16 at 15:27
  • 1
    Worked perfectly, thanks so much for the walkthrough, really helped me out here. – Batman Mar 15 '16 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.