Sliding Date Range Filter in the Data View Web Part
I had a client request to filter items from a Data View Web Part based on a date column. The tricky part was that they wanted items to return only if the value in the date column was in the coming week. So I needed some way to filter out all dates that were earlier than today or later than today + 7 days. The date column in this example is “Bid Date.”
The scenario I created has 4 items from 2 different lists:
- Item 1 – no bid date selected (should not show)
- Item 2 – bid date within 7 day range (should show)
- Item 3 – bid date in the past (should not show)
- Item 4 – bid date in the future, beyond the 7 day range (should not show)
With no filters, my data view web part shows all 4 items:
From SharePoint Designer, open the page with the data view web part and click the chevron in the upper-right corner. Click “Filter:” and note that currently there are no filters applied:
The Filter Criteria dialog box opens.
We will add two clauses, one to filter out any item with a Bid Date earlier than today, and another to filter out any Bid Date with a date beyond 7 days from today. Click to add a new clause:
The first one is easy—we required that the Bid Date be greater than or equal to the current date. Note that this filter alone will filter out empty Bid Dates as well as Bid Dates in the past:
For the second filter, we must go a little deeper to achieve the dynamic date of “today plus 7 days.” Click the Advanced Button and note the existing XPath, which is our “greater than or equal to today” clause we just created:
We can now modify this to add the “today plus 7 days” filter. The highlighted portion below is the new part, and the red circle is the + 7, which is key to the equation:
The result is a nice filter that shows only items with Bid Dates between today and 7 days out:
Labels: sharepoint, xsl
4 Comments:
AlerpetlyPrew
afof
Hi,
Do you have any idea on date range filter by user? E.g, I have order list, then I want to select date range between 1/12/2009 to 31/12/2009, then the order list will be displayed according to user input.
Thanks in advance.
Regards
Cindy Tan
Hi your XPATH has a bug, be careful and correct that, let's run a case of error: supose the date 2008-29-30, so wi will add 7 days, then:
the xpath translate erases the hyphens and leavs then convert to number ( which would result in 20082930)
Then, if you added 7 days, you'll get a 20082937 which is not a valid date and you are comparing against a valid date field...
I think that there should be a better way of doing this...
comments: isaacchacon@hotmail.com
Adding a number to $Today formatted as yyyyMMdd doesnt work as 25th June 2009 (20090625) with 10 added would be the 35th June 2009.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home