I'd hate to leave the blog dormant for the Thanksgiving weekend, so as I get ready to head to my in-laws place for a few days I'll leave you with a few small snippets of code.
It's possible to use the Query String (URL) Filter to filter certain web parts on your page which can be very handy, but sometimes you need to include controls (like a drop-down box) inside the page to filter the information shown in the web parts.
First the code for the actual drop-down box:
Putting this code into a CEWP will present you with a drop-down box that will let you pick a state and will re-direct you to the ".../States.aspx?State=SELECTEDSTATE" page.<b>State</b><br>
<select id="SelectFilter" name="State" onChange="javascript:doFilter(this.value)"/>
<option value="Arizona">Arizona</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option>
<option value="Idaho">Idaho</option>
<option value="Montana">Montana</option>
<option value="Nevada">Nevada</option>
<option value="Oregon">Oregon</option>
<option value="Utah">Utah</option>
<option value="Washington">Washington</option>
</select>
<script type="text/javascript">
function doFilter(x)
{ window.location = "http://path.to/States.aspx?State=" + x; }
</script>
Now that you've got your variable sent to the URL string, it's time to put it to use filtering the web parts on the page. Luckily, this is something that SharePoint makes easy.
Add the Query String (URL) Filter web part to the page. It doesn't matter where you put this one as it will not be displayed on the page.
- The only setting that NEEDS to be configured in the "Modify Shared Web Part" menu is the "Query String Parameter Name" setting. Just type in the title of the variable you want to use, in this case it would be "State" to match the "States.aspx?State=WHATEVER" URL.
- Now all you need to do is pick which web parts you want to filter with that variable. To do this, you need to be looking at the page in "Edit Mode", the click "edit" on the title bar of the Web Part you want to filter, then select "Connections", then select "Get Sort/Filter From", then pick the name you gave the Query String (URL) Filter Web Part. When you're asked what field from the Web Part you want to filter on, choose the field that matches the query string (in this case it's "State"). Then when you select a different state from the drop-down the page will reload with information for that state.


0 comments:
Post a Comment