Is there any way to dynamically change event template in FullCalendar?
Update. What I want is to specify new event html (e. g. in eventRender callback) and make FullCalendar to use it for my event rendering. Something like this:
eventRender: function(event, element, view) {
var template = '<div class="customEvent"></div>';
return $.parse(template);
}
Tried the sample above - didn't work.
You can add meta information on the event, like classes, and style accordingly:
events: [{
title: 'Blue Event',
start: '2014-06-01',
description: 'Lorem ipsum lorem ipsum',
class: 'blue main'
}]
And the CSS:
.fc-event.blue {}
.fc-event.main {}
On eventRender insert the classes with
eventRender: function (event, element) {
element.addClass(event.class)
}
And append more content like:
if (event.description) {
element.find('.fc-event-inner')
.append("<div class='desc'>" + event.description + "</div>");
}
$(document).ready(function () {
$('#calendar').fullCalendar({
header: { left: '', center: '', right: '' },
defaultDate: '2014-06-12',
eventRender: function (event, element) {
if (event.description) {
element.find('.fc-event-inner')
.append("<div class='desc'>" + event.description) + "</div>";
}
element.addClass(event.class)
},
events: [{
title: 'Blue Event',
start: '2014-06-01',
description: 'Lorem ipsum lorem ipsum',
class: 'blue main'
}, {
title: 'More Blue',
start: '2014-06-01',
description: 'More lorem ipsum',
class: 'blue main'
}, {
title: 'Long Event',
start: '2014-06-07',
end: '2014-06-10',
class: 'red main'
}, {
title: 'Meeting',
start: '2014-06-12T10:30:00',
end: '2014-06-12T12:30:00',
class: 'blue main'
}, {
title: 'Lunch',
start: '2014-06-12T12:00:00',
class: 'blue main'
}, {
title: 'Birthday Party',
start: '2014-06-13T07:00:00',
class: 'red main'
}, ],
});
});
body {
background-color: #eaefb5;
font-family: sans-serif;
}
.fc-event-time, .fc-event-title {
padding: 0 1px;
float: left;
clear: none;
margin-right: 10px;
}
.fc-event.main {
border: 5px solid #bbb;
margin: 5px;
padding: 3px
}
.fc-event.red {
background-color: #f85032;
}
.fc-event.red .fc-event-title {
font-family: Tahoma;
font-size: 1.2em
}
.fc-event.blue {
background: #87e0fd;
background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #87e0fd), color-stop(40%, #53cbf1), color-stop(100%, #05abe0));
background: -webkit-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
background: -o-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
background: -ms-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
background: linear-gradient(to bottom, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#87e0fd', endColorstr='#05abe0', GradientType=0);
}
.fc-event.blue .fc-event-title {
font-size: 2em;
color: #EEE;
text-shadow: 2px 2px 4px #300000;
}
.fc-event.blue .desc {
font-size:.8em;
float:left;
clear:both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.0.3/fullcalendar.css">
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.0.3/fullcalendar.min.js"></script>
<div id="calendar"></div>
The eventRender callback function can modify element, return a brand new DOM element that will be used for rendering instead, or it can return false, which will prevent the event from being rendered at all.
http://fullcalendar.io/docs/event_rendering/eventRender/
Example here: http://jsfiddle.net/3E8nk/506/
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2014-06-12',
editable: true,
eventRender: function(event, element, view) {
return $('<div>' + event.title + '</div>');
},
events: [
{
title: 'All Day Event',
start: '2014-06-01'
},
{
title: 'Long Event',
start: '2014-06-07',
end: '2014-06-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-06-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-06-16T16:00:00'
},
{
title: 'Meeting',
start: '2014-06-12T10:30:00',
end: '2014-06-12T12:30:00'
},
{
title: 'Lunch',
start: '2014-06-12T12:00:00'
},
{
title: 'Birthday Party',
start: '2014-06-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2014-06-28'
},
]
});
Use the eventRender(callback) function to change the event template. Here is how you can add a tip to the event:
eventRender: function(event, element, view) {
element.qtip({
content: event.description
});
}
With this function you can fully customize any detail of the event that is displayed including adding a complete new event template. For more details check out the documentation:
http://fullcalendar.io/docs/event_rendering/eventRender/
In Version v4 of FullCalendar the arguments have changed (https://fullcalendar.io/docs/eventRender)
eventRender: function(info) {
var node = document.createElement('div');
node.append(document.createTextNode(info.event.title));
return node;
}
If you want to prevent an event from rendering just return false
eventRender: function(info) {
return false;
}
You may append new information like this
eventRender: function( event, element, view ) {
element.find('.fc-title').append('<span class="yourCSS"></span> ');
}
Related
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.
I have this grid that has headers in vertical position (phone header), and when I try to resize the header's width to 50px I don't get to see the header text anymore (but if I manually drag the header to the left I can see the header text), so my question is: How can I always show the header text even after setting the header size to smaller size.
Please take a look at this line of code:
{ text: 'Phone' dataIndex: 'phone', cls: 'grid-header-phone' }
Now I'm simply adding a smaller width to it like this:
{ text: 'Phone', width: 50, dataIndex: 'phone', cls: 'grid-header-phone' }
Here's a working example: FIDDLE
here's the code I'm using:
Ext.application({
name : 'Fiddle',
launch : function() {
var store = Ext.create('Ext.data.Store', {
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa#simpsons.com", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"bart#simpsons.com", "phone":"555-222-1234" },
{ 'name': 'Homer', "email":"homer#simpsons.com", "phone":"555-222-1244" },
{ 'name': 'Marge', "email":"marge#simpsons.com", "phone":"555-222-1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', width: 50, dataIndex: 'phone', cls: 'grid-header-phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
}
});
and here's the css code:
.grid-header-phone .x-column-header-text {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
/* transform doesn't work on inline elements */
display: inline-block;
/* need to hard code a height for this to work */
/* you could use Ext.util.TextMetrics if you needed to dynamically determine the text size */
height: 40px;
}
.x-ie8 .grid-header-phone .x-column-header-text {
/* IE8 doesn't have css transform */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
}
use display:inline-flex instead of inline block.
I would like the label text on my Highcharts treemap to be white with a black border, so that it is consistent and clearly visible on all colors. Is this possible? I have played with the textShadow options, and it looks okay (although not great) in Chrome, but it looks very unprofessional in Internet Explorer. See the fiddle here:
https://jsfiddle.net/k1hohozg/4/
$(function () {
$('#container').highcharts({
title: "",
series: [{
type: "treemap",
data: [
{
name: 'Name One',
value: 20,
color: "#FFFF00"
}, {
name: 'Name Two',
value: 20,
color: '#000099',
}, {
name: 'Name Three',
value: 1,
color: '#007799',
}, {
name: 'Name Four',
value: 1,
color: '#FFCC00',
}
],
levels: [{
level: 1,
dataLabels: {
enabled: true,
align: 'center',
style: {
fontSize: '20px',
color: '#FFFFFF',
textShadow: "0 0 3px #000, 0 0 3px #000",
}
},
}],
}],
});
})
I do not want to use the "contrast" option because I need all the text to look the same, hence white with a black border. What is the best way to make this look better in all standard browsers?
Thanks!
There is no default Highcharts way to deal with IE rendering poorly text-shadow. It is possible to set useHTML to true and add multiple labels that will be imitating shadow. (Looks fine in Chrome, Firefox and IE11).
Example: http://jsfiddle.net/yzLavxc9/2/
....
dataLabels: {
useHTML: true,
formatter: function () {
return '<div class=dataLabelContainer><div style="position: absolute; top: -1px; left: 1px; color: #000;">'+this.key+'</div><div style="position: absolute; top: 1px; left: 1px; color: #000;">'+this.key+'</div><div style="position: absolute; top: 1px; left: -1px; color: #000;">'+this.key+'</div><div style="position: absolute; top: -1px; left: -1px; color: #000;">'+this.key+'</div><div style="position: absolute; color: #fff;">'+this.key+'</div></div><div style="color: #fff;">'+this.key+'</div></div>';
},
enabled: true,
align: 'center',
style: {
fontSize: '20px',
....
I think this is not possible with the textShadow attribute wich is not well interpreted with IE. However you can add a background on your labels to be more visible :
$(function() {
$('#container').highcharts({
title: "",
series: [{
type: "treemap",
data: [{
name: 'Name One',
value: 1,
color: "#FFFF00"
}, {
name: 'Name Two',
value: 1,
color: '#000099',
}],
levels: [{
level: 1,
dataLabels: {
enabled: true,
align: 'center',
borderRadius: 5,
backgroundColor: 'rgba(255, 255, 255, 1)',
style: {
fontSize: '20px',
color: '#000',
}
},
}],
}],
});
})
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<div id="container"></div>
You can inspire yourself from the documentation:
http://api.highcharts.com/highcharts#plotOptions.area.dataLabels.backgroundColor
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.
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