Content Query Web Part and Dates

MVP

Whilst more of an advanced user rather than a developer myself, I think only a developer can answer my question.  I am trying to display a list of entries from my custom list where the [Order Date] is this week (i.e. after Monday in the current week).  I don't believe this can be done via the query in CQWP, however I was hoping I could get users to input the week start date into a control on the page and use that field to set the value in the CQWP.

 

Otherwise the CQWP gives exactly what is needed, just need a way to set the date in the query to Monday.  Any advice?  Ideally no code solutions.

7 Replies
You can use the content Query web part for this however you might want to try using the Search results or Content Search web part. Then you can use Display templates instead of xsl. And specify queries through the interface.
Thanks for the tips. The 7 day filtering around today won't work in this scenario as the view needs to only show current week not last 7 days. Current week being Monday to Sunday. So on a Monday, I need to see only today, on Tuesday today and yesterday, etc.

Would definitly go for search and displaytemplates it is much faster than CQWP you need to invest some time in it but it makes your users happy.

 

kr,

 

Paul

So if you create a start of the week calculated column you can filter by
Date > start of week and date <= today

One way to go around it would be to define a query that would get items from previous 7 days to next 7 days: that way you would be safe on Sunday (getting items from the past week) as well as on Monday (getting items from the upcoming week). You could then sort items ascending by the date and do filtering in XSLT. The ddwrt namespace contains some date manipulation functions that could help you with that. It's not trivial but it's definitely doable. It's worth noting that this approach would work if the list of items is not huge and retrieving items from -7 days to + 7 days wouldn't return hundreds of items.

 

Hope this helps,

 

Waldek

The performance really depends on the size of the list and the scope of the query. Also with search you have to take into account the index latency which, depending on your search configuration, might be causing not all items being returned.