Showing posts with label 14. Show all posts
Showing posts with label 14. Show all posts

2 Oct 2012

Sharepoint. Advanced filtering of SharePoint list view by URL

This post is about advanced filtering of SharePoint list view (or XsltListViewWebPart) by setting parameters in URL, such as:

  • filter list view by part of the word (contains) in URL
  • filter list view by date range in URL
  • and so on.

The key is to use CAML GetVar Element.

For example, View with this <Query> will show list items whose titles contains specified in URL parameter “ProjectTitle” substring (Lists/Projects/AllItems.aspx?ProjectTitle=crm):

<Query>
  <Where>
    <Contains>
      <FieldRef Name="Title"/>
      <Value Type="Text">
        <GetVar Scope="Request" Name="ProjectTitle"/>
      </Value>
    </Contains>
  </Where>
</Query>

This View has two problems:

  1. It is possibly to set such View <Query> via SharePoint Designer, List Definition, custom code, but not using standard SharePoint web UI.
  2. If URL doesn’t contain “ProjectTitle” parameter, the View will show nothing.