Quickly filter a List/Document Library View using URL

February 27th, 2008 | Categories: Flash, JavaScript, SharePoint

This one’s very useful when you’re having a lot of items in a list or document library and you need a quick filter.

If you’ll select the filter field it can happen that it will load for a long time. So lately I’m using URL. Suppose you have a long list of contacts and you need to find a contact named Boris.

In the AllItems.aspx – view of the page, add parameters

?FilterField1=[Field Name]&FilterValue1=[Value]

You can add more filterfield and filtervalue parameters to apply filters to more fields (FilterField2, FilterValue2, …)

The only trick is to know the Field Name like it’s saved in SharePoint. You can see this in the list settings page (click on a column name and check URL) or just make a manual filter for the first time.

In my case to find a contact with First Name Boris, I’d go to

http://[site_URL]/lists/contacts/AllItems.aspx?FilterField1=FirstName&FilterValue1=Boris

I’m always browsing a document library with filtering by specific document type. So I’ve created a simple script. Just add a Content Editor Webpart to your homepage, edit its source and add the following code (just update the url to your document library (docLibUrl):

<script type="text/javascript">
function docLib(dropdown) {
  var vtype = dropdown.options[dropdown.selectedIndex].value;
  var docLibUrl = "/Shared Documents/Forms/AllItems.aspx";
  var filterField = "DocIcon"
  if (vtype != ‘Select’) {
    document.location=docLibUrl+"?FilterField1="+filterField+"&FilterValue1="+vtype;
  }
}
</script>
<select style="margin:10px; 0px;" id="DocumentTypes" onchange="docLib(this)">
<option value="Select">Select document type</option>
<option value="Select">– Office 2007 –</option>
<option value="docx">Word 2007</option>
<option value="xlsx">Excel 2007</option>
<option value="pptx">PowerPoint 2007</option>
<option value="Select">– Office 2003 –</option>
<option value="doc">Word 2003</option>
<option value="xls">Excel 2003</option>
<option value="ppt">PowerPoint 2003</option>
<option value="Select">– Other –</option>
<option value="pdf">Acrobat (PDF)</option>
</select>

Oznake ponudnika Technorati: ,