full calendar using jquery in MVC - fullcalendar

I am trying to understand full calendar.. i don't know how to use methods like selection or colour. Could any one please give me a example for colour my each event day by different colour .and on clicking over the day tile a message should ask us to add a event.
I had read http://fullcalendar.io/docs/ but can't understand .how to change that.
<link href="~/Content/calendar/fullcalendar.css" rel="stylesheet" />
<link href="~/Content/calendar/fullcalendar.print.css" rel="stylesheet" media='print' />
<link href="~/Content/jquery-ui.min.css" rel="stylesheet" />
<style>
body {
margin: 40px 10px;
padding: 15px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
<div id='calendar'></div>
#section scripts{
<script src="~/Scripts/calendar/moment.min.js"></script>
<script src="~/Scripts/calendar/jquery.min.js"></script>
<script src="~/Scripts/calendar/fullcalendar.min.js"></script>
<script src="~/Scripts/calendar/jquery-ui.custom.min.js"></script>
<script>
$(document).ready(function () {
$('#calendar').fullCalendar(Duration,'00:30:00');
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2015-02-12',
selectable: true,
selectHelper: true,
select: function (start, end) {
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
slotDuration:'00:00:15',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2015-02-01'
},
{
title: 'Long Event',
start: '2015-02-07',
end: '2015-02-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-02-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-02-16T16:00:00'
},
{
title: 'Conference',
start: '2015-02-11',
end: '2015-02-13'
},
{
title: 'Meeting',
start: '2015-02-12T10:30:00',
end: '2015-02-12T12:30:00'
},
{
title: 'Lunch',
start: '2015-02-12T12:00:00'
},
{
title: 'Meeting',
start: '2015-02-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2015-02-12T17:30:00'
},
{
title: 'Dinner',
start: '2015-02-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2015-02-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2015-02-28'
}
]
});
});
</script>
}

The following code is used to give colors to different events in fullcalender.
{
title: 'All Day Event',
start: '2015-02-01',
backgroundColor: '#000'
},
{
title: 'Long Event',
start: '2015-02-07',
end: '2015-02-10',
backgroundColor: '#DDD'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-02-09T16:00:00',
backgroundColor: '#CCC'
},
give a backgroundColor parameter with color code to particular event.
and following code is used, if you want to open a popup for a new event when you click on the event title.
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: '<?php echo $view; ?>',
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
$.ajax({
url:"<?php echo site_url("controller/function_name");?>/"+convert_date(start),
cache:false,
data:"event_name="+convert_date(start),
success:function(data){
//alert(data);
if(data=="holiday" || data=="no"){
$( ".modalbox" ).on( "click", function() {
});
//$("#day_"+convert_date(start)).css("background-color","#f00");
$("#event_date").val(start);
summary();
summary_change($("#reminder").val());
//$("#date_of_end").val(convert_date_mdy(start));
//$("#summary_date").val(convert_date_mdy(start));
}
else{
$( ".modalbox" ).on( "click", function() {
});
$( ".modalbox" ).trigger( "click" );
$("#event_date").val(start);
summary();
summary_change($("#reminder").val());
//$("#date_of_end").val(convert_date_mdy(start));
//$("#summary_date").val(convert_date_mdy(start));
}
}
});
$("#addSchedule").submit(function(){
title=$("#shift").val();
if (title!="") {
date=convert($("#event_date").val());
end_date=convert(end);
$("#event_date").val(date);
$("#end_date").val(end_date);
$("#allDay").val(allDay);
calendar.fullCalendar('renderEvent',
{
title: title,
start:$("#event_date").val(),
end: end,
allDay: allDay
},
);
}
$("#holder").hide();
//return false;
});
calendar.fullCalendar('unselect');
},
editable: true,
events: <?php echo $result;?>,
eventClick: function(event) {
$.ajax({
url:"<?php echo site_url("controller/function_name");?>/"+event.event_id,
cache:false,
data:"event_name="+event.title,
success:function(data){
$("#inline1").html(data);
$( ".modalbox1" ).on( "click", function() {
});
$( ".modalbox1" ).trigger( "click" );
}
});
},
});
eventClick parameter will be in act, when you click on particular event on fullcalender.

Related

Fullcalendar change weekend backcolor

i created a new MVC asp.Net webpage and for testing i added Fullcalendar 5.1.
For testing i put all the stuff in index.html:
<!DOCTYPE html>
<html lang='en'>
<head>
<link rel="stylesheet" href="~/lib/fullcalendar/main.css" />
<script src="~/lib/fullcalendar/main.js"></script>
<meta charset='utf-8' />
<style>
.fc-sun {
background-color: blue;
}
.fc-sat {
background-color: red;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
initialDate: '2020-07-07',
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
events: [
{
title: 'All Day Event',
start: '2020-07-01'
},
{
title: 'Long Event',
start: '2020-07-07',
end: '2020-07-10'
},
{
groupId: '999',
title: 'Repeating Event',
start: '2020-07-09T16:00:00'
},
{
groupId: '999',
title: 'Repeating Event',
start: '2020-07-16T16:00:00'
},
{
title: 'Conference',
start: '2020-07-11',
end: '2020-07-13'
},
{
title: 'Meeting',
start: '2020-07-12T10:30:00',
end: '2020-07-12T12:30:00'
},
{
title: 'Lunch',
start: '2020-07-12T12:00:00'
},
{
title: 'Meeting',
start: '2020-07-12T14:30:00'
},
{
title: 'Birthday Party',
start: '2020-07-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2020-07-28'
}
]
});
calendar.render();
});
</script>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
But the backcolor wont change :-(
if i put some other variables in like this:
.fc .fc-col-header-cell-cushion { /* needs to be same precedence */
padding-top: 10px; /* an override! */
padding-bottom: 21px; /* an override! */
}
the header padding changes.
What iam doing wrong?
the fiddle is the example: http://jsfiddle.net/rajesh13yadav/nf9whojL/1/
Can you please help me?
EDIT:
As a workaround i use this:
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
initialDate: '2020-07-07',
businessHours: {
// days of week. an array of zero-based day of week integers (0=Sunday)
dow: [1, 2, 3, 4, 5], // Monday - Friday
start: '00:00', // a start time (09am in this example)
end: '00:00', // an end time (6pm in this example)
},
and the style is:
<style>
.fc .fc-non-business {
color: red;
background: green;
opacity: 0.1;
}
</style>
But why i cant set the other properties?
In version 5.1 the classes are .fc-day-sat and fc-day-sun
Setting the background-color for those classes works fine.

Highcharts: How to toggle between different xaxis having individual plotbands, onclick rangeselector buttons

I have a chart with daily values of the month of October.
Two buttons: week and month.
Week plotband has to be identical with month plotband: First 2 days are green, next 5 days are blue in month plotband. When selecting week, the range date 1-7 should be same colour green and blue.
Highcharts.chart('container', {
chart: {
type: 'column',
},
title: {
text: 'How long time a TR has been placed in stages longer than 48 hours'
},
legend: {
enabled: true
},
subtitle: {
text: 'Input - verify should max be 48 hours = green zone'
},
data: {
csv: document.getElementById('csv').innerHTML
},
plotOptions: {
column: {
},
series: {
dataLabels: {
enabled: false,
format: '{point.y}'
}
}
},
tooltip: {
},
rangeSelector: {
buttonSpacing: 10,
enabled: true,
inputEnabled: false,
selected: 1,
buttons: [{
type: 'week',
count: 1,
text: 'Week'
}, {
type: 'month',
count: 1,
text: 'Month'
}],
},
xAxis: [{
id: 'one',
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S.%L',
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
plotBands: [{
from: 1538352000000,
to: 1538524800000,
color: '#E8F5E9'
}, {
from: 1538524800000,
to: 1538870400000,
color: '#E0ECEC'
}, {
from: 1538870400000,
to: 1539475200000,
color: "#FFFDE7"
}, {
from: 1539475200000,
to: 1540944000000,
color: "#FFEBEE"
}],
}, {
id: 'two',
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S.%L',
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
plotBands: [{
from: 1538352000000,
to: 1538524800000,
color: '#E8F5E9'
}, {
from: 1538524800000,
to: 1538870400000,
color: '#E0ECEC'
}],
}],
yAxis: {
min: 0,
max: 100,
title: {
text: 'TRADING RECORDS',
}
}
});
Please see jsfiddle
Is there a way to toggle between two xaxis with different plotBands: when clicking on the 'week' button, one plotband will display and when clicking on the 'month' button another plotband will display. So the colours of the plotband is relative to the dates?
I assume I have to use event functions like setExtremes and afterSetExtremes, but not sure how to do it?
Thanks much appreciated for help.
I managed to simulate the output with this function:
events: {
afterSetExtremes: function (e) {
if (e.trigger == "rangeSelectorButton" &&
e.rangeSelectorButton.text == "Week") {
// it is your button that caused this,
// so setExtrememes to your custom
// have to do in timeout to let
// highcharts finish processing events...
setTimeout(function () {
Highcharts.charts[0].xAxis[0].setExtremes(1538352000000, 1538524800000)
}, 1);
}
},
}
But it only work when selecting specific: setExtremes(1538352000000, 1538524800000)
I think a scaleable solution for any 7 days would require some sort of exception functionality for remove current plotband on xaxis with addplotband
Updated fiddle
I added custom buttons instead: https://forum.highcharts.com/viewtopic.php?t=31649
<div class="btn-group" data-toggle="buttons">
<button class="btn btn-custom" id="one">48 hours</button>
<button class="btn btn-custom" id="two">7 days</button>
<button class="btn btn-custom" id="three">14 days</button>
<button class="btn btn-custom" id="four">31 days</button>
<button class="btn btn-custom" id="all">All</button>
</div>
<div id="containerbenchmark"></div>
$.get('bm.csv', function (bmcsv) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'containerbenchmark',
type: 'areaspline',
},
title: {
text: ''
},
legend: {
enabled: true
},
subtitle: {
text: 'Input - verify - close should max be 48 hours = green zone'
},
data: {
csv: bmcsv,
},
plotOptions: {
areaspline: {
stacking: 'normal'
},
series: {
dataLabels: {
enabled: false,
format: '{point.y}'
}
}
},
tooltip: {
/*headerFormat: '<span style="font-size: 16px">{point.key}</span><br/>',
pointFormat: '<span style="font-size: 14px; color:{series.color}">{series.name}: <span style="font-size: 14px">{point.y} {point.total}</span><br/>',
footerFormat: '<span style="font-size: 16px">{point.total}</span><br/>',*/
shared: true,
useHTML: true,
formatter: function () {
var tooltip = '<table><span style="font-size: 16px">' + Highcharts.dateFormat('%e/%b/%Y',
new Date(this.x)) + '</span><br/><tbody>';
//loop each point in this.points
$.each(this.points, function (i, point) {
tooltip += '<tr><th style="font-size: 14px; color: ' + point.series.color + '">' + point.series.name + ': </th>' +
'<td style="font-size: 14px; text-align: right">' + point.y + '</td></tr>'
});
tooltip += '<tr><th style="font-size: 16px">Total: </th>' +
'<td style="font-size: 16px; text-align:right"><span>' + this.points[0].total + '</span></td></tr>' +
'</tbody></table>';
return tooltip;
}
},
rangeSelector: {
selected: 2,
enabled: true,
inputEnabled: true,
inputDateFormat: "%m/%d/%Y",
inputEditDateFormat: "%m/%d/%Y",
inputDateParser: function (s) {
return Date.UTC(
parseInt(s.substr(6, 4)),
parseInt(s.substr(0, 2) - 1),
parseInt(s.substr(3, 2)),
12
)
}
},
navigator: {
enabled: true
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S.%L',
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
plotBands: [{
from: 1538352000000,
to: 1538524800000,
color: '#cae8cc',
label: {
text: '> 48 hours',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}, {
from: 1538524800000,
to: 1538870400000,
color: '#d0e2e2',
label: {
text: '> 7 days',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}, {
from: 1538870400000,
to: 1539475200000,
color: "#fff9b3",
label: {
text: '> 14 days',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}, {
from: 1539475200000,
to: 1540944000000,
color: "#ffb3be",
label: {
text: '> 31 days',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}],
},
yAxis: {
min: 0,
title: {
text: 'TRADING RECORDS',
}
}
}, function (chart) {
// apply the date pickers
setTimeout(function () {
var rangeSelector = $('#containerbenchmark input.highcharts-range-selector');
rangeSelector.datepicker({
autoclose: true,
todayHighlight: true
}) /*.datepicker('update', new Date())*/ ;
var inputMin = rangeSelector.filter('[name=min]');
var inputMax = rangeSelector.filter('[name=max]');
inputMin.datepicker().on("changeDate", function (event) {
console.log(inputMin.datepicker("getDate"));
console.log(inputMin.datepicker("getUTCDate"));
});
}, 1000);
});
$('#one').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1538352000000,
1538524800000
);
});
$('#two').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1538524800000,
1538870400000
);
});
$('#three').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1538870400000,
1539475200000
);
});
$('#four').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1539475200000,
1540944000000
);
});
$('#all').click(function () {
chart.xAxis[0].setExtremes(
event.min,
event.max
);
});
});

fullcalendar get event details on event click

I created a calendar using fullcalender all the events (tasks) are displaying on it.
Now i want to open a form which display the event's details, how can i taking the event details by clicking on it?
my code:
<script>
$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2014-09-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'Meeting',
start: '2014-09-12T10:30:00',
end: '2014-09-12T12:30:00'
}
]
});
});
</script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
Check the full calendar documentation. Here is the link.
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2014-09-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'Meeting',
start: '2014-09-12T10:30:00',
end: '2014-09-12T12:30:00'
}
],
eventClick: function(event) {
if (event.title) {
alert(event.title);
}
}
});

jqgrid rowattr not applying class

I want to apply background color to row of jqGrid row based on value of column, however the basic rowattr is not applying class to rows.
Below is the code (for simplicity I have removed the condition on which color needs to be applied)
jQuery("#employeeSalarysGrid").jqGrid({
height: 250,
url: 'http://localhost:50570/api/Test/Get',
mtype: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; },
id: "0",
cell: "",
repeatitems: false
},
datatype: "json",
colNames: ['Id', 'Bank Name', 'Bank Name', 'Employee name', 'Joining date', 'Salary amount', 'Comments'],
colModel: [
{ name: 'Id', align: "center", hidden: true },
{ name: 'BankName', index: 'BankName', align: 'center', editable: false },
{
name: 'BankId', index: 'BankId', align: "center", hidden: true, required: true,
viewable: true, editrules: { edithidden: true, required: true },
editable: true,
edittype: 'select',
editoptions: {
dataUrl: '/api/Test/GetBanks',
buildSelect: function (data) {
var response = jQuery.parseJSON(data);
var s = '<select>';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var bank = response[i];
s += "<option value=" + bank.BankId + ">" + bank.Name + "</option>";
}
}
return s + "</select>";
}
}
},
{ name: 'EmployeeName', align: "center", editable: true, editrules: { required: true } },
{ name: 'JoiningDate', align: "center", editable: true, editrules: { custom: true, custom_func: datecheck },
formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'd-M-y' }, edittype: 'text', editable: true,
editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker({ dateFormat: 'd-M-y' }); }, 200); } }
},
//{ name: 'cdate', index: 'cdate', width: 80, align: 'right', formatter: 'date', srcformat: 'yyyy-mm-dd', newformat: 'm-d-Y', edittype: 'text', editable: true, editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker(); }, 200); } } },
{ name: 'SalaryAmount', align: "center", editable: true, editrules: { required: true } },
{ name: 'Comments ', align: "center", editable: true }
],
gridview: true,
autoencode: true,
ignorecase: true,
loadonce: true,
sortname: "InstallmentDate",
sortorder: "asc",
viewrecords: true,
rowNum: 10,
rowList: [10, 15, 20],
pager: '#employeeSalarysPager',
caption: "Employee Salary list",
rowattr: function (rd) {
return { "class": "rowClass" };
//alert("hi");
}
});
CSS style :
<style type="text/css">
.rowClass { color: blue; background-image: none;}
</style>
Note: If I uncomment //alert statement, it shows alert message 5 times. It means rowattr is getting invoked for each row, however css class is not getting applied.
Regards,
Abhilash
The rowattr do works correctly, but if you want that the class will be applied on selected rows too then you should change CSS rule to the following
.ui-widget-content .rowClass { color: blue; background-image: none; }
see the demo.

ASP.NET Calendar

I have a problem with calendar,I want to paint special days different color For example
On calendar
03.06.2011 Day--->blue
04.06.2011 day---->red
12.06.2011-04.07.2011 Days ----> yellow
More than one color I want to use selected day
You can use javascript to do that,
Refer to JSFiddle Here
You can add custom special day,
$(document).ready(function () {
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2014-07-04',
editable: true,
events: [{
title: 'All Day Event',
start: '2014-07-01'
}, {
title: 'Long Event',
start: '2014-07-07',
end: '2014-07-10'
}, {
id: 999,
title: 'Repeating Event',
start: '2014-07-09T16:00:00'
}, {
id: 999,
title: 'Repeating Event',
start: '2014-07-16T16:00:00'
}, {
title: 'Meeting',
start: '2014-07-12T10:30:00',
end: '2014-07-12T12:30:00'
}, {
title: 'Lunch',
start: '2014-07-12T12:00:00'
}, {
title: 'Birthday Party',
start: '2014-07-13T07:00:00'
}, {
title: 'Click for Google',
url: 'http://google.com/',
start: '2014-07-28'
}],
eventAfterAllRender: function (view) {
//Use view.intervalStart and view.intervalEnd to find date range of holidays
//Make ajax call to find holidays in range.
var fourthOfJuly = moment('2014-07-04','YYYY-MM-DD');
var holidays = [fourthOfJuly];
var holidayMoment;
for(var i = 0; i < holidays.length; i++) {
holidayMoment = holidays[i];
if (view.name == 'month') {
$("td[data-date=" + holidayMoment.format('YYYY-MM-DD') + "]").addClass('holiday');
} else if (view.name =='agendaWeek') {
var classNames = $("th:contains(' " + holidayMoment.format('M/D') + "')").attr("class");
if (classNames != null) {
var classNamesArray = classNames.split(" ");
for(var i = 0; i < classNamesArray.length; i++) {
if(classNamesArray[i].indexOf('fc-col') > -1) {
$("td." + classNamesArray[i]).addClass('holiday');
break;
}
}
}
} else if (view.name == 'agendaDay') {
if(holidayMoment.format('YYYY-MM-DD') == $('#calendar').fullCalendar('getDate').format('YYYY-MM-DD')) {
$("td.fc-col0").addClass('holiday');
};
}
}
}
});
});
For changing the colour, you can edit background on .holiday in css file
body {
margin: 0;
padding: 50px 0 0 0;
font-family:"Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
font-size: 14px;
}
#calendar {
width: 100%;
}
.holiday {
background: lightgray;
}
Hope it can help you

Resources