Calendar 默认情况下,日历将全部展开

Calendar 默认情况下,日历将全部展开,calendar,sharepoint-2010,Calendar,Sharepoint 2010,有人知道如何在默认情况下将日历视图全部展开吗??查看了大量有关如何使用SP 2007而不是SP 2010执行此操作的信息。这不是最好的方法,但它很有效,请在CEWP或内联页面中添加以下脚本: <script type="text/javascript"> _spBodyOnLoadFunctionNames.push("myFuncafterLoad"); function myFuncafterLoad(){var OldCalendarNotify4a = SP.UI.App

有人知道如何在默认情况下将日历视图全部展开吗??查看了大量有关如何使用SP 2007而不是SP 2010执行此操作的信息。

这不是最好的方法,但它很有效,请在CEWP或内联页面中添加以下脚本:

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("myFuncafterLoad");

function myFuncafterLoad(){var OldCalendarNotify4a = SP.UI.ApplicationPages.CalendarNotify.$4a;SP.UI.ApplicationPages.CalendarNotify.$4a = function (){myFunctoExpandCalendar();OldCalendarNotify4a();}}

function myFunctoExpandCalendar(){try{var aTags=document.getElementsByTagName('A');for(i=0;i<aTags.length;i++){try{if(aTags[i].evtid=="expand_collapse"){aTags[i].click();break;}}catch(err){ alert('Bad Call at' + aTags[i].href);}}}catch(err){alert(err.message);}}</script>

_spBodyOnLoadFunctionNames.push(“myFuncafterLoad”);
函数myFuncafterLoad(){var OldCalendarNotify4a=SP.UI.ApplicationPages.CalendarNotify.$4a;SP.UI.ApplicationPages.CalendarNotify.$4a=函数(){myFunctoExpandCalendar();OldCalendarNotify4a();}

函数myFunctoExpandCalendar(){try{var aTags=document.getElementsByTagName('A');for(i=0;iKuldeep),感谢这个脚本!我稍微修改了它,通过删除中断并检查锚文本是否为“折叠”,来扩展日历的所有行。如果不是“折叠”,将执行单击。请注意,每行只需单击一个项目。否则,您可能会切换回“折叠”

将CEWP添加到日历页面的另一个有问题的副作用是,您将丢失“更改视图”下拉列表。您必须使用日历功能区更改视图

我还想找到一个更强大的解决方案,但这里是我的略微改进的解决方案:

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("myFuncAfterLoad");

function myFuncAfterLoad() {
    var oldCalendarNotify4a = SP.UI.ApplicationPages.CalendarNotify.$4a;

    SP.UI.ApplicationPages.CalendarNotify.$4a = function () {
        oldCalendarNotify4a();
        myFuncToExpandCalendar();
    }
}

function myFuncToExpandCalendar() {
    try {
        var aTags = document.getElementsByTagName('A');
        for (i = 0; i < aTags.length; i++) {

            if ((aTags[i].evtid == "expand_collapse") && (aTags[i].innerText != "collapse")) {
                (aTags[i]).click();
            }
        }
    }
    catch (err) {
        alert(err.message);
    }
}

</script>

_spBodyOnLoadFunctionNames.push(“myFuncAfterLoad”);
函数myFuncAfterLoad(){
var oldCalendarNotify4a=SP.UI.ApplicationPages.CalendarNotify.$4a;
SP.UI.ApplicationPages.CalendarNotify.$4a=函数(){
oldCalendarNotify4a();
myFuncToExpandCalendar();
}
}
函数myFuncToExpandCalendar(){
试一试{
var aTags=document.getElementsByTagName('A');
对于(i=0;i
此选项有两个选项。将以下一个或另一个选项粘贴在CEWP中

第一个选项将覆盖用于在显示展开/折叠链接之前确定要显示多少项的函数。在下面的示例中,我已将其设置为100,以确保在我的用例中,我甚至从未看到展开/折叠按钮,并且始终会渲染每个项

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');

function WaitForCalendarToLoad() 
{   
    SP.UI.ApplicationPages.SummaryItemRenderer.prototype.$2u = function () 
    {
            ULSvSp: ;
            if (!this.$1A_1) this.$1A_1 = 100;
            return this.$1A_1
        }
}
</script>

_spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');
函数WaitForCalendarToLoad()
{   
SP.UI.ApplicationPages.SummaryItemRenderer.prototype.$2u=函数()
{
ULSvSp:;
如果(!this.$1A_1)this.$1A_1=100;
还这个。1美元1美分
}
}
第二个选项覆盖calendar notify事件,以便在呈现所有项目后,脚本将找到第一个日历实例,并调用其expand all函数。这将确保默认情况下展开每个单元格,但仍将显示折叠链接

<script type="text/javascript">

 _spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');

function WaitForCalendarToLoad() 
{   
    var old$4a = SP.UI.ApplicationPages.CalendarNotify.$4a;

    SP.UI.ApplicationPages.CalendarNotify.$4a = function () 
    {
        old$4a();

        ctrl = SP.UI.ApplicationPages.CalendarInstanceRepository.firstInstance();

        if (ctrl) {
            ctrl.expandAll();
        }
    }
}
</script>

_spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');
函数WaitForCalendarToLoad()
{   
var old$4a=SP.UI.ApplicationPages.CalendarNotify.$4a;
SP.UI.ApplicationPages.CalendarNotify.$4a=函数()
{
旧的$4a();
ctrl=SP.UI.ApplicationPages.CalendarInstancePository.firstInstance();
如果(ctrl){
ctrl.expandAll();
}
}
}
我正在使用这个(2013年):


.ms cal nav{显示:无;}
LoadSodByKey(“SP.UI.ApplicationPages.Calendar.js”),函数(){
设置超时(ExpandCalendar,500);
});
函数ExpandCalendar(){
//始终扩展
$('.ms-cal-nav:has(img[src$=“/expandbttn.gif”])。每个(函数(){this.click();});
设置超时(ExpandCalendar,1000);
}

它每秒钟运行一次,虽然不是很好,但似乎完成了这项工作

因此,基于Andrew Peacko提供的原始解决方案(可能是针对SP2010),我能够将这些作为陈述点,为SP2016制定一个可行的解决方案

最大的区别似乎是,CalendarNotify在SP2016中被弃用,这导致许多基于SP2010的解决方案在较新版本中无法工作。如果使用重叠日历,则会有额外的复杂性;重叠日历上事件的HTML元素似乎直到页面加载过程的很晚才呈现-即使使用sp.SOD等待页面上最后一个源代码脚本(sp.ui.socialribbon.js),也没有足够长的时间等待这些脚本可用。我相信这就是为什么大多数(如果不是所有)依赖这些脚本可用的SP2016日历解决方案必须使用setTimeout()或setInterval()的原因.在我们的例子中,对于第二个解决方案,我们需要等到所有覆盖的事件都呈现在日历上,然后再调用日历的expandAll()函数,否则它将无法工作

综上所述,这是我在上述原始SP2010解决方案的基础上提出的两个SP2016兼容解决方案。第一个解决方案完全删除了展开/折叠链接,并确保日历始终展开以显示所有事件

第一个方法覆盖设置“折叠项限制”(强制显示“展开/折叠”链接的项数)的内置函数


函数setCalendarCollapseItemLimit(){
//配置日历的“折叠项目限制”,使其始终显示
//默认情况下,所有项目都将显示,并且从不折叠它们。
SP.UI.ApplicationPages.SummaryItemRenderer.prototype.$3V_1=function(){
ULSvSp:;
如果(!这是10亿美元){
//这将“折叠项目限制”设置为100个事件
这10亿美元=100;
}
还这个。10亿美元1;
}
}
//加载必要的脚本后调用我们的函数(本例中为sp.ui.applicationpages.calendar.js)。
ExecuteOrderLayUntillScriptLoaded(setCalendarCollapseItemLimit,“sp.ui.applicationpages.calendar.js”);
这种方法的优点是即使是新的,它也会保持扩展
function expandCalendar() 
{
    var calendar = SP.UI.ApplicationPages.CalendarInstanceRepository.firstInstance();
    if (calendar && typeof calendar.expandAll === 'function') {
        calendar.expandAll();
    }
<style>
.ms-cal-nav { display:none; }
</style>

<script type="text/javascript">
  LoadSodByKey("SP.UI.ApplicationPages.Calendar.js", function () {
    window.setTimeout(ExpandCalendar, 500);
  });

  function ExpandCalendar() {
    // expand always
    $('.ms-cal-nav:has(img[src$="/expandbttn.gif"])').each(function() { this.click(); });

    window.setTimeout(ExpandCalendar, 1000);
  }
</script>
<script type="text/javascript">
    function setCalendarCollapseItemLimit() {
        // Configure the calendar's "collapse item limit" so that it always shows
        // all items by default and never collapses them.
        SP.UI.ApplicationPages.SummaryItemRenderer.prototype.$3V_1 = function() {
            ULSvSp:;
            if(!this.$1B_1) {
                // This sets the "collapse item limit" to 100 events
                this.$1B_1 = 100;
            }
            return this.$1B_1;
        }
    }

    // Call our function once the necessary script is loaded (sp.ui.applicationpages.calendar.js in this case).
    ExecuteOrDelayUntilScriptLoaded(setCalendarCollapseItemLimit, "sp.ui.applicationpages.calendar.js");
</script>
<script type="text/javascript">
    function expandAllCalendarItems() {
        var cal = SP.UI.ApplicationPages.CalendarInstanceRepository.firstInstance();
        if (cal) {
            cal.expandAll();
            return true;
        } else {
            return false;
        }
    }

    // We need to use setInterval() here so that the calendar will be expanded when it becomes available and
    // after any overlaid calendar events have been rendered. An interval of 1400 seems to be sufficient for this.
    // We store the return value so that we can clear it (stop the loop) once we’ve successfully expanded it.
    var expItemsInterval = setInterval(function() {
        var retVal = expandAllCalendarItems();
        if (retVal === true) {
            // Calendar was expanded - clear interval
            clearInterval(expItemsInterval);
        }
    }, 1400);
</script>