Expression Evaluation Time: ms / Round trip: ms
How to build a user-defined filter with MatchPoint
15. Aug
by Stefan Category:

In this blog post I'd like to demonstrate how to build a user-defined filter with MatchPoint 3.0. As an example I will use a news page in the style of any major news company. The page displays news feeds categorized in different topics, such as politics, economy, sport, science, travel, living, health, etc. The user should be able to pick some of these topics in order to create a personal view of the news feed. This view will be persisted and therefore available for further visits.


Display the News

In our example the news items are stored in a SharePoint list of type Announcement. The news topics are represented by a multi-choice column. To display the feed we use a MatchPoint Composite Web Part.

SharePoint news list setup:

  1. Create a SharePoint list of type "Announcement"
  2. Go to the list settings
  3. Create a choice column "Topic" with enabled multi selection.

Composite Web Part configuration:

  1. Add a new Composite Web Part to the page and go to the Web Part configuration via the ribbon button.
  2. Set the "PageSize" to 5.
  3. Add a "ListDataProvider" and select the news list created above.
  4. Add a "PatternTransformer" with the following "RowTemplate":

      <div style="color:#aaa;">

Apply a Filter

We use another SharePoint list to persist the user defined-filters. One list item will be representing a user's personal filter. The topics that define the filter will be stored in a multi-choice column. In the Composite Web Part we use a Field Condition on the List Data Provider to filter the news items with the topics stored in the user filter item.

SharePoint filter list setup:

  1. Create a SharePoint list of type "Custom List".
  2. Go to the list settings
  3. Create a choice column "Topic" with enabled multi selection (add the same choices as you added in the news list setup).

List Data Provider configuration:

  1. Open the configuration of the Composite Web Part and select the List Data Provider.
  2. Add an "Or" condition.
  3. Add a new "FieldCondition" inside the "Or" condition.
  4. Use "Topic" as name.
  5. Use "EqualTo" as operator.
  6. Use "AutoDetect" as field type.
  7. Use "Ignore" as empty rule.
  8. Use the following expression to extract the current user's filter values:

      .Where("Author", "=", SPHelper.GetCurrentUser().ID)

This expression makes use of the list query expression extension provided by the MatchPoint Expression Engine. The Where method is available on objects of type SPList. The query defined with the Where and Select method call will be executed as CAML query.

Since we set the empty rule to "Ignore" no error will occur if the current user has no filter item defined yet.

If the expression of the Field Condition returns more than one value, multiple conditions will be combined with the operator defined by the parent group condition (in our case "or"). If the expression returns the topics "Sport" and "Politics" the following query will be generated:

(Topic = Sport) OR (Topic = Politics)

Edit the Filter

To complete our example we have to build an interface where the user can define the filter. Add a page where we can place a MatchPoint Form Web Part.

Add the Form Web Part:

  1. Create a new page.
  2. Add a MatchPoint Form Web Part to the page and go to the Web Part configuration via the ribbon.
  3. Use "Back" as close action.
  4. Add a list item data adapter.
  5. Select the settings in ListUrl
  6. Use "Current user" in RunAsUser.
  7. Use the following expression as "ItemExpression":

      .Where("Author", "=", SPHelper.GetCurrentUser().ID)
    ? Web.Lists.Settings
        .Where("Author", "=", SPHelper.GetCurrentUser().ID)
    : null

    Again we make use of the list query extensions and query for the item of the current user. If the user has not defined a filter yet, we return null in order to create a new item. The "ItemExpression" result null will be interpreted like the "Create item" selection in the drop down box.

  8. Select the "Fields" node of the form configuration.

  9. Add a new field of the type "FieldRef" and select "Topic" from the drop-down box.
  10. In order to provide the user a convenient way to edit his favorite topics, add the following HTML snippet to the header or footer template of the Composite Web Part and replace <page url> with your page url created above:

    <a onclick="$$.Opener.OpenItemDialog('_layouts/somepage.aspx')">
      Edit My Topics


22.09.2011 09:55
How could this be expanded to use the tags structure as the topics? Also, how could you incorporate and and or conditions?
05.10.2011 11:22
In order to use MatchPoint tags three changes on the solution have to be done. Firstly, use tags to categorize the news items. Secondly, replace the choice fields on user-defined filter item editor form with appropriate tag choice fields. Lastly, use a tag condition instead of the field condition on the list data provider. Hint: The tag condition accepts an expression which provides the "filter tags". Use this expression to provide the user defined tags:

.Where("Author", "=", SPHelper.GetCurrentUser().ID)
02.02.2012 03:44
Stefan, this aproach works perfect as long as you only have one such webpart on a page.
Do you have any suggestion how to place multiple webparts with user-defined filters on a page?

As far a i know, we have no access to the webpartid within an expression. any hints?

This blog is about technical and non-technical aspects of the product MatchPoint and other SharePoint topics.

If you would like to post an article or if you have an idea for a post, please contact us.

Matthias Weibel
09.04.2018 01:12
Link is updated and works now. | Goto Post
09.04.2018 12:21
Link doesn't work. Could anyone explain what does... | Goto Post
14.03.2018 02:05
Hi Markus
We I use the config for SiteCollectionSe... | Goto Post
Reto Jeger
04.10.2017 09:15
Hello Reiner,
Thanks for pointing out the missing ... | Goto Post
29.09.2017 09:56
Hi, I downloaded the ZIP-file for MatchPoint Versi... | Goto Post