Jquery FullCalendar,在输出中显示周数和日期名称



我有一个Jquery FullCalendar。我能够从json中获得值的行和列的总值。我想将周数添加到行输出,将天名添加到列输出

例如:-这是我的行输出值950 500 550 200,这些是我的列输出值700 300 200 250 200 250

为现在的工作而奋斗!!

我希望生成如下输出:-

对于行值(W 44)950、(W 45)500、(W 46)550、(W 47)200总计:(2200)以及类似的列值<strong](周日)700(周一)300(周二)300(周三)200(周四)250(周五)200(周六)250>

完整代码:-

var baseEvent;
var $calendar = $('#calendar').fullCalendar({
 weekNumbers: true,
header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
},
editable: true,
selectable: true,
selectHelper: true,
eventRender: eventRenderCallback,
viewRender: viewRenderCallback,
eventAfterAllRender: eventAfterAllRenderCallback,
defaultView: 'month',
events: [
    {"title":"500","start":"Oct 1 2015"},   
    {"title":"50","start":"Oct 2 2015"},
    {"title":"500","start":"Oct 3 2015"},   
    {"title":"50","start":"Oct 4 2015"},
    {"title":"500","start":"Oct 6 2015"},   
    {"title":"50","start":"Oct 7 2015"},
    {"title":"500","start":"Oct 8 2015"},   
    {"title":"50","start":"Oct 9 2015"},
    {"title":"500","start":"Oct 10 2015"},   
    {"title":"50","start":"Oct 11 2015"},
    {"title":"500","start":"Oct 12 2015"},   
    {"title":"50","start":"Oct 13 2015"},
    {"title":"500","start":"Oct 14 2015"},   
    {"title":"50","start":"Oct 15 2015"},
    {"title":"500","start":"Oct 16 2015"},   
    {"title":"50","start":"Oct 17 2015"},
    {"title":"500","start":"Nov 1 2015"},   
    {"title":"50","start":"Nov 2 2015"},
    {"title":"100","start":"Nov 3 2015"},   
    {"title":"50","start":"Nov 4 2015"},
    {"title":"100","start":"Nov 5 2015"},   
    {"title":"50","start":"Nov 6 2015"},
    {"title":"100","start":"Nov 7 2015"},   
    {"title":"50","start":"Nov 8 2015"},
    {"title":"100","start":"Nov 9 2015"},   
    {"title":"50","start":"Nov 10 2015"},
    {"title":"100","start":"Nov 11 2015"},   
    {"title":"50","start":"Nov 12 2015"},
    {"title":"100","start":"Nov 13 2015"},   
    {"title":"50","start":"Nov 14 2015"},
    {"title":"100","start":"Nov 15 2015"},   
    {"title":"50","start":"Nov 16 2015"},
    {"title":"100","start":"Nov 17 2015"},   
    {"title":"50","start":"Nov 18 2015"},
    {"title":"100","start":"Nov 19 2015"},   
    {"title":"50","start":"Nov 20 2015"},
    {"title":"100","start":"Nov 21 2015"},   
    {"title":"50","start":"Nov 22 2015"},
    {"title":"100","start":"Nov 23 2015"},   
    {"title":"50","start":"Nov 24 2015"},
    {"title":"500","start":"Dec 1 2015"},   
    {"title":"50","start":"Dec 2 2015"}
]
});
var rowTotals = [];
var columnTotals = [];
var offset = 0;
function eventRenderCallback(event,element){
var viewDateMonth = $('#calendar').fullCalendar('getDate').getMonth();
if(event.start.getMonth() == viewDateMonth){
    addToDateArray(event.start.getDate(), parseInt(event.title));
}
}
function eventAfterAllRenderCallback(view){
var total = 0;
for (var i = 0; i < 6; i++){
    total += rowTotals[i];
    var label = $("#rows label:nth-child(" + (i+1) + ")");
    label.html(rowTotals[i]);     
}
for (var i = 0; i < 7; i++){
    var label = $("#cols label:nth-child(" + (i+1) + ")");
    label.html(columnTotals[i]);     
}
$("#total").html("("+total+")");
}
function viewRenderCallback(view,element){
offset = $("tr.fc-week.fc-first td.fc-other-month").length;
rowTotals = [0,0,0,0,0,0];
columnTotals = [0,0,0,0,0,0,0];
if(view.name == "agendaDay"){
    $("#rows label").show();
    $("#cols label").hide();
    $("#cols label:nth-child(" + (view.start.getDay()+1) + ")").show();
}else if(view.name == "agendaWeek"){
    $("#cols label").show();
    $("#rows label").hide();
    var row = Math.floor((view.start.getDate() + offset - 1) / 7);
    $("#rows label:nth-child(" + (row+1) + ")").show();
}else {
    $("#cols label").show();
    $("#rows label").show();
}
}                   
function addToDateArray(date,num){
var pos = date + offset;
var row = Math.floor((pos - 1) / 7);
var col = (pos - 1) % 7
rowTotals[row] += num;
columnTotals[col] += num;
}

请编辑小提琴以获得任何解决方案。谢谢

由于您在fullcalendar中使用了weekNumbers选项,它会为您计算周数。分数它们可以使用$(".fc week numberdiv")从dom中检索。您可以通过一个简单的日期名称索引数组来获取日期。

Fiddle

function eventAfterAllRenderCallback(view){
    var total = 0;
    for (var i = 0; i < 6; i++){
        total += rowTotals[i];
        var label = $("#rows label:nth-child(" + (i+1) + ")");
        var week = $(".fc-week-number div").eq(i).html();
        label.html("(W"+(week)+") " + rowTotals[i]);     
    }
    var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'];
    for (var i = 0; i < 7; i++){
        var label = $("#cols label:nth-child(" + (i+1) + ")");
        label.html("(" + dayNames[i] + ") " + columnTotals[i]);     
    }
    $("#total").html("("+total+")");
}

相关内容

  • 没有找到相关文章

最新更新