简体   繁体   English

SharePoint视图仅自动显示当前月份?

[英]SharePoint View to automatically show only the current month?

I need to create a view that will automatically change from month to month to show only the current month (ie if current month is July - show items posted in July). 我需要创建一个视图,该视图将自动随月份变化,以仅显示当前月份(即,如果当前月份为7月-显示7月发布的项目)。 Currently I have a view set up, but I have to manually change the month each time it changes (it's set up based on the first day of the current month and the last day of current month). 目前,我已经设置了视图,但是每次更改时我都必须手动更改月份(它是根据当月的第一天和当月的最后一天设置的)。

Thanks 谢谢

You can do this by turning the problem on its head. 您可以通过转而解决问题。

First you need to add two calculated columns that will work out the start an the end of the month. 首先,您需要添加两个计算出的列,以计算月初和月底。 (This example uses [Due Date] but you can use any date/time column) (此示例使用[到期日期],但您可以使用任何日期/时间列)

"Start of Month"  =DATE(YEAR([Due Date]), MONTH([Due Date]), 1)

"End of Month"    =DATE(YEAR([Due Date]), MONTH([Due Date])+1,1)-1

Then you setup a filter in your view for 然后,您在视图中设置了一个过滤器

"Start of Month" is less than or equal to [Today]
 AND
"End of Month" is greater than or equal to [Today]

How To Use Filters in SharePoint to show items in the current Calendar Month 如何在SharePoint中使用筛选器以显示当前日历月中的项目

Create a CC "NextMonth" that adds one month to your date =DATE(YEAR(Modified),MONTH(Modified)+1,"1") 创建一个CC“ NextMonth”,将您的日期添加一个月= DATE(YEAR(Modified),MONTH(Modified)+1,“ 1”)

create a view "ThisMonth" with this filter 使用此过滤器创建视图“ ThisMonth”

"NextMonth" is greater than [Today] “ NextMonth”大于[今天]

this will always return the current month. 这将始终返回当前月份。 can also be allpied to Year, to return current year 也可以分配给Year,以返回当前年份

Create a CC "NextYear" that adds one year to your date =DATE(YEAR(Modified)+1,MONTH(Modified),"1") 创建一个CC“ NextYear”,将日期添加一年= DATE(YEAR(Modified)+ 1,MONTH(Modified),“ 1”)

create a view "ThisYear" with this filter 使用此过滤器创建视图“ ThisYear”

"NextYear" is greater than [Today] “下一年”大于[今天]

Now the trick is to return a view for last Month. 现在的诀窍是返回上个月的视图。 Let me know if you figure this out 让我知道你是否能解决这个问题

EDIT: Please see Ryan's solution below, it's more comprehensive. 编辑: 请参阅下面的Ryan解决方案,它更全面。

I believe there is no out of the box solution for that. 我相信没有开箱即用的解决方案。 One trick can be to write code in default view which would actually set the month for you or redirect to any other view. 一种技巧是在默认视图中编写代码,这实际上可以为您设置月份或重定向到任何其他视图。 Something like 就像是

SPWeb web = SPContext.Current.Web;
string[] monthViewUrls = { "url1", "url2", ... };
string currentMonthUrl = monthViewUrls[DateTime.Now.Month-1];
Response.Redirect(currentMonthUrl );

Hope this helps. 希望这可以帮助。

Can you live with the calendar view? 您可以使用日历视图吗? That shows current month by default. 默认情况下显示当前月份。 Maybe you can start with that and try to customize it in SPD - it might retain its current month behavior. 也许您可以从此开始并尝试在SPD中对其进行自定义-它可能会保留其当前月份的行为。

Start of Previous Month =DATE(YEAR(Created),MONTH(Created)-1,"1") 上个月的开始= DATE(YEAR(创建),MONTH(创建)-1,“ 1”)

End of Previous Month =DATE(YEAR(Created),MONTH(Created),-1) 上个月末= DATE(YEAR(创建),MONTH(创建),-1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM