Tuesday, November 4, 2008

Filter between two dates (date range) with the Data view Webpart

To filter a date range in sharepoint:

1. What you need on a page:
a. 2 Date Filter webparts
b. 1 list to be filtered

2. Open the page w/ SPD, convert the list to be filtered to DataView (Convert to DataView will give you a lot more columns to choose in the DataView’s Filter critiera, as oppose to going to Insert->Sharepoint Controls->DataView. However, you will still not see a ‘[StartDate]’ and ‘[EndDate]’ when you go to Filter on the DataView's 'Common Date View Tasks'.

3. Now it's time to create the 'StartDate' and 'EndDate' parameters:
Under the DataView's 'Common Date View Tasks', choose Filter, click on the 'Click here to add a phase', scroll down and click on 'Create a new parameter'




4. Now we are ready to configure the filter for the Date View:



5. In the code view, you should see the newly added parameters:
<ParameterBinding Name="StartDate" Location="QueryString(StartDate)" DefaultValue=""/>
<ParameterBinding Name="EndDate" Location="QueryString(EndDate)" DefaultValue=""/>


6. Now we need to setup the connections from the DataView so it knows where to get the data for the parameters. Click on the little arrow for ‘Common Dataview tasks’, go to webpart connections (Note: makes sure you choose the ‘Get Parameters From’)



When done going through the Web part Connections Wizard, you should see something like this:



7. Almost done. Now go to the browser and edit page. Click on the date filters to connect the webparts. The Data needs to know where to get the filter values. Even though the connections were setup from the DataView, you still have to setup the filter fields from the Date Filters. Note the consumer field name is the parameter we setup earlier. Do the same for each date filter, one for the 'StartDate' parameter, one for the 'EndDate' parameter.



8. Done. Final result could be something like this:

40 comments:

Skibutt said...

This is a great guide, however i am struggling with it.

Once I get the date filter working, any alterations to the page seem to break the web part connections and i get no results in the data view web part.

I must have created my page a dozen times and there's always something i miss and even number formatting in the DVWP breaks it !

Pete

Delzey said...

@Skibutt - I am having the same issue, not sure what is happening but even applying CSS to the date web part the list just goes away... I noticed if I complete all formatting to the page as well as all of the items that need to be tweaked before completing step #7, all is good to go.

This means I do everything I need to do to the page after step #6 and then perform step #7 absolutely last and all works fine.

Skibutt said...

mhh, well at least i'm not the only one. My advice is to create a version up to point 6, save it as _template or something and then create your real file name from that one (file save as) that way you can tweak the formatting after and just have to recreate the date links.

I'm also seemingly not able to get this to work with a linked data source.

rtg said...

Thanks. This is exactly what I need.
Unfortunately, I also had the "list disappearing" issue before I read the comments. At least I know what to do.

Chris. said...

I can get this to work, if I use Greater than, or less then for the filter choices.

but doing this, if there is an entry for example on the 12th.
And the users select a start date of the 12th, it won't find it.

I've tried using greater than or equal too in the filter choice, but it doesn't work.

Any ideas?

Andreas said...

I also have problems getting this to work with a linked data source. Any idea on how to fix this?

Anonymous said...

Andreas, I have the same problem, can't get it to work with linked data source :S

Cindy Tan said...

Please help. I got this error An error occurred processing the data view. The XslText property is empty. when I in Step 7 after I did for first Date Filter web part

Anyone got idea to solve it?

Yanling said...

Cindy, try undoing your xsl change. you prolly have a wrong xsl tag somewhere.

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Yanling said...

Guys, since i am working with the standard MOSS version nowadays, I was forced to figure out another way of doing this. It's clean and neat and actually a lot better since you don't have to recreate the dataview everytime. If it's helpful for anyone i'll post it. Otherwise between my 3 jobs, I most likely won't if no one needs it. LOL!

Grantly said...

@Yanling - Yes, could you please post your updated version? This is exactly what I'm looking for, but I'm forced to work with Standard MOSS also. Thanks!

Yanling said...

Sorry for the delay: a better way of doing this:
http://yanlinglei.blogspot.com/2010/02/filter-between-two-dates-using-dataview.html

Anonymous said...

nice post. I would love to follow you on twitter.

Susan said...

Awesome, thank you!

Susan said...

Awesome, thank you!

Anonymous said...

great post!!! a++

Anonymous said...

Hello,

This is a message for the webmaster/admin here at yanlinglei.blogspot.com.

Can I use some of the information from your post above if I provide a backlink back to this site?

Thanks,
Alex

Yanling said...

@Alex, sure.

Anonymous said...

Hi,

Nice Article.
But there is some prob in webpart connection.
in webpart connection When i select get parameters from n click next button then all the options are disabled and i am not able to connect that webpart.

Anonymous said...

el mensaje muy Гєtil
http://www.sexfg.com/
Boldy

Singam said...

in 2003 we dont have calendar control.. how to go about in it.. please help. thanks.

Anonymous said...

top [url=http://www.c-online-casino.co.uk/]uk online casinos[/url] coincide the latest [url=http://www.casinolasvegass.com/]free casino games[/url] manumitted no deposit reward at the foremost [url=http://www.baywatchcasino.com/]unshackle casino games
[/url].

Anonymous said...

[url=http://loveepicentre.com/articles.php][img]http://loveepicentre.com/uploades/photos/10.jpg[/img][/url]
free dating sties [url=http://loveepicentre.com]scam proof russian dating sites[/url] online dating informative outline
new dating site in holland [url=http://loveepicentre.com/success_stories.php]dating websites for sexy bbw[/url] 0 largest 2008 dating site
western europe dating [url=http://loveepicentre.com/testimonials.php]gay men dating[/url] dominican free dating sites

Anonymous said...

You really make it appear really easy along with your
presentation but I to find this topic to be really something which I feel I
would by no means understand. It sort of feels too complicated
and extremely huge for me. I am having a look ahead for your subsequent post, I will try to get the hang of it!


Feel free to visit my web-site: internet dating

Anonymous said...

Hey just wanted to give you a quick heads up. The words in your content seem to be
running off the screen in Ie. I'm not sure if this is a formatting issue or something to do with browser compatibility but I figured I'd post to let you know.

The style and design look great though! Hope you get the issue solved soon.

Many thanks

Feel free to surf to my homepage ... online free dating sites

Anonymous said...

You made certain fine points there. I did a search on the theme and found nearly all
persons will agree with your blog.

Here is my webpage dating international
My web site - formatemas.com

Anonymous said...

I will right away grab your rss as I can't find your e-mail subscription link or newsletter service. Do you've any?
Please let me know in order that I could subscribe.
Thanks.

my blog ... www.live-cricket-score.net

Anonymous said...

Pretty section of content. I just stumbled upon your website and in accession capital to assert
that I acquire in fact enjoyed account your blog posts.
Anyway I will be subscribing to your feeds and even I achievement you access consistently fast.


My page ... bmi calculator female

Anonymous said...

Thanks for your publication. I also feel that laptop computers have
become more and more popular currently, and now are sometimes the only type of
computer utilised in a household. This is due to the fact that at the same time potentially they are becoming more and more economical, their processing power is growing to the point where
there're as trong as desktop computers from just a few years ago.

My blog :: http://auto-bookmarks.de/search.php/all/利用者:ChristelV - 田中研究室 (JAIST)

Anonymous said...

Hey there! I've been following your site for a long time now and finally got the courage to go ahead and give you a shout out from Atascocita Texas! Just wanted to say keep up the fantastic work!

my homepage; elderscrollsonline-wiki.com

Anonymous said...

Good blog post. Things i would like to bring about is that computer memory has to be purchased but if
your computer can no longer cope with what you do along with it.

One can mount two random access memory boards
with 1GB each, as an example, but not certainly one of 1GB and one with 2GB.
One should look for the s documentation for the PC to make
certain what type of memory space is needed.

Look at my blog: single

Anonymous said...

One thing I would really like to discuss is that weightloss
system fast can be achieved by the right diet and exercise.
Someone's size not simply affects the look, but also the overall quality of life. Self-esteem, major depression, health risks, and also physical ability are damaged in fat gain. It is possible to just make everything right whilst still having a gain. If this happens, a problem may be the perpetrator. While a lot food instead of enough workout are usually at fault, common medical ailments and widely used prescriptions may greatly help to increase size. Thanks for your post

My page - http://wikiadvocacy.org

Anonymous said...

This really answered my drawback, thank you!

Also visit my website ... online dating website free

Anonymous said...

Interesting blog post. The things i would like to bring
about is that computer memory has to be purchased should your computer cannot cope
with anything you do by using it. One can mount two random access memory
boards having 1GB each, as an illustration, but not one of 1GB
and one with 2GB. One should always check the s
documentation for own PC to make certain what type of storage it can take.



Also visit my website: on line dating sites

Anonymous said...

Today, I went to the beachfront with my kids. I found a sea shell and gave
it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She
put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this
is totally off topic but I had to tell someone!

My web page: dating service free

Anonymous said...

Great web site. Lots of useful info here. I am sending it to several friends ans also sharing in delicious.
And naturally, thanks for your sweat!

Here is my web site :: http://wenzlitschke.de/index.php?title=Benutzer:KrystleLa

Anonymous said...

how can i do this in Foundation ?

Anonymous said...

e cig forum, e cigarette forum, electronic cigarette, electronic cigarettes, e cigarette, e cig