How to display current date using full calendar - javascript

I am new to jquery.
I am using full calendar for showing events for a month.
However I am unable to display current date above the calendar as shown in various example.
Below is my code:
$(document).ready(function () {
$('#calendar').fullCalendar({
defaultView: 'month',
editable: false,
eventSources: [
{
url: '/Admin/AjaxRequest/CalendarDate/',
type: 'POST',
data: {
start: '0',
end: '0',
id:id
},
},
]
});
});

Titleformat and Header documentations have all the answers you need.
Set a header where you specify where you want your title and then specify in titleformat how you want this title to be displayed.
Answering this even though #Xaerxess point in the comment is valid..

Related

how to alert next month date

I'm using "fullcalendar" plug- https://fullcalendar.io/ in order to display tours on calendar
when user click next/pre button, how do i ALERT the next/pre full date?
for instant, if the calendar show me the current day (2019-06-03) and i click "next" then alert will display 2019-07-01. clicking "pre" will display 2019-05-01
my code:
<div id="calendar"></div>
<script>
$(document).ready(function() {
var initialLocaleCode = 'en';
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
eventLimit: true,
editable: false,
events: [
{
title: 'tour 1',
start: '2019-05-05',
end: '2019-05-11',
className: 'bg-warning'
},{
title: 'title for tour num 2',
start: '2019-05-19',
end: '2019-05-25',
className: 'bg-purple'
},{
title: '3td tour title',
start: '2019-05-16',
end: '2019-05-21',
className: 'bg-info'
}
]
});
});
</script>
I'm not sure why you'd need to do this, since the new date will already be displayed at the top of your calendar.
However, putting that aside, one way to achieve it is to handle the viewRender event. This will occur anytime either the date range or the type of view is changed on the calendar, and fires just before the new view is actually displayed on the screen. As per the documentation, the view object supplied in the callback contains the the start and end dates which are about to be displayed.
You could write something like this:
viewRender: function( view, element )
{
alert(view.start.format("YYYY-MM-DD"));
}
Here's a working demonstration: http://jsfiddle.net/8bxqzfev/

Show more than 1 day in Fullcalendar Day View

I am trying to use the Full Calendar component to show 3 days in agenda Day view or eventually using the vertical resource view.
I tried using the example custom view but no luck.
Is it possible to show 3 days, one below another in the day view ?
I am using this constructor, but I don't want the days to be next to each other, but underneath each other.
$('#calendar').fullCalendar({
defaultView: 'agendaDay',
defaultDate: '2017-12-07',
editable: true,
selectable: true,
eventLimit: true, // allow "more" link when too many events
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaDay,agendaTwoDay,agendaWeek,month'
},
views: {
agendaTwoDay: {
type: 'agenda',
duration: { days: 3 },
// views that are more than a day will NOT do this behavior by default
// so, we need to explicitly enable it
//groupByResource: true
//// uncomment this line to group by day FIRST with resources underneath
groupByDate: true
}
}
You can't show the days below each other in an agenda style view, no. Its whole layout scheme is oriented horizontally. You can easily show them side-by-side, in the normal agenda style.
The vertical resource view provided by the Scheduler plug-in is essentially the same as the agenda view, but with each day split out into sub-columns for each specified Resource.
If you want days to appear one below the other, your only option is the "list"-style view. This will show things vertically, but you lose the time grid.
This code will achieve both of those types of view with a 3-day span, so you can see the difference:
views: {
agendaThreeDay: {
type: 'agenda',
duration: {
days: 3
},
buttonText: '3 day agenda'
},
listThreeDay: {
type: 'list',
duration: {
days: 3
},
buttonText: '3 day list'
}
},
Here is a working demo: http://jsfiddle.net/sbxpv25p/104/
If neither of those satisfy what you want, then your only other option is to make a completely custom view type (see the second half of this documentation page: https://fullcalendar.io/docs/views/Custom_Views/). This is a complex and time-consuming task, so before embarking on such a thing you should consider whether one of the built-in types of view will really be satisfactory - they do convey the necessary information to the user, which is the main purpose of a calendar, even if it wasn't quite in exactly the layout you had imagined.
In order to show multiple days in Agenda View ( Day ) just add - and + how many hours you want ... For example -24 H for a day ahead and +24 H for a day after your selected day. Something like this:
views: {
firstView: {
type: 'agendaDay',
minTime: '-12:00:00',
maxTime: '36:00:00',
slotDuration: '00:30:00',
},
}
views: {
timeGridFourDay: {
type: 'timeGrid',
duration: { days: 4 },
buttonText: '4 day'
}
},
and add it to header:
header: {
left: 'prev,next',
center: 'title',
right: '.....,timeGridFourDay'
},
https://fullcalendar.io/docs/custom-views

Jquery FullCalendar not loading in popup

I created a popup with my custom css and js show hide functions. Now I want to place the calendar to that popup.
I tried
$(document).on('click', '.cliker', function () {
$(".succes_msg").remove();
$show = $(this).attr('pkid');
$(this).addClass('activer');
$("input[name=startTime]").val($(this).find("span").eq(0).html()).timepicker();
$(".addbtn").attr('pkId', $show);
$('#calendar').fullCalendar({
defaultView: 'basicWeek',
aspectRatio: 1.5,
header : {
left : 'prev,next',
center: 'title',
right : ''
},
dayOfMonthFormat: 'ddd MMM/MM',
firstDay: 4,
eventLimit: true,
render: true,
height: 250,
buttonText: {
today: 'today',
month: 'month' },
eventSources: [{
url: '{{URL::to(route('get_calender_data'))}}',
type: 'get',
data: {cinema: 0}
}],
});
$(".modelPophldr,.editShow").show();
$(".editShow").animate({'margin-top': '25px'});
});
Like above there I am showing the popup after the fullcalendar rendering.
How to fix it?
Edit...
Right now the calendar is coming with only right and left arrows, but the calendar is not loaded. When I click on the next button it will show the calendar with events perfectly.
display: none removes the element out of the flow of the HTML so you need to call your event when your element becomes visible that why your plugin is working when you click on arrows
try to initialize your plugin after
$(".modelPophldr,.editShow").show();

FullCalendar.io timeformat not working with eventsources

I'm using the calendar plugin fullcalendar . Now I want to show my date from my activities in format H(:mm)" but my code isn't working for some reason.
My code is in c#.
I've used this javascript code to get it working.
$('#calendar').fullCalendar({
header: {
left: 'prev,title,next',
right: 'today,basicDay,basicWeek,month'
},
lang: 'nl',
defaultDate: new Date(),
eventLimit: true, // allow "more" link when too many events
fixedWeekCount :false,
eventSources: [
{
url: '/Groups/GetActivities',
type: 'GET',
data: {
startdate: "2014-12-01",
enddate: "2014-12-31",
groupid: #Model.Group.Id,
},
allDay:false,
timeFormat:"h:mm",
color: '#EAE9E0'
}
]
});
I've read the documentation about timeformat here.
My request returns data in this format:
[{"title":"Bergmonicursus - Val d\u0027anniviers","start":"2015-01-03T12:00:00","end":"2015-02-03T08:00:00","url":"/activities/95/detail?groupid=156","allDay":false}]
Can someone please explain to me what I'm doing wrong. My end result of the activity has 12 as hour format and not 12:00 or 12:30 if I hardcode it.
timeFormat is a top level property in the fullcalendar options object. It can't be an event property.
So put it here
$('#calendar').fullCalendar({
header: {
left: 'prev,title,next',
right: 'today,basicDay,basicWeek,month'
},
lang: 'nl',
defaultDate: new Date(),
eventLimit: true, // allow "more" link when too many events
fixedWeekCount :false,
eventSources: [
{
url: '/Groups/GetActivities',
type: 'GET',
data: {
startdate: "2014-12-01",
enddate: "2014-12-31",
groupid: #Model.Group.Id,
},
allDay:false,
//timeFormat:"h:mm", // X--- Not here
color: '#EAE9E0'
}
],
timeFormat:"h:mm", // <---- Here
});
And if you need to change on a event to event basis, you have to use eventRender. (and do it manually).

Change full calendar output?

I am working on a full calendar on a webpage. Currently, the layout of each day block is:
Time
Title
Description
but I would like title goes first and then time. But I cannot find anywhere I can make this change in the code.
$(document).ready(function() {
$("#cal").fullCalendar({
header: {
left: 'prev,next',
right: 'month,agendaDay'
},
aspectRatio: 2,
editable: false,
timeFormat: 'h:mmt{-h:mmt}',
eventTextColor: 'black',
eventBackgroundColor: '#FFFF77',
allDayDefault: false,
eventSources: [{
url: 'path/to/fullcalendar',
color: 'green',
textColor: 'black'
}],
eventRender: function(event, element) {
element.find('.fc-event-title').html(event.title + "<br/>" + event.description).text();
}
});
});
So anyone can help me figure out where should I modify to make the change to swap title and time?
Thank you
Inside of eventRender you need to alter the element layout so the time comes after the title. Something like this:
eventRender : function(event, element) {
var time = element.find('.fc-event-time').detach();
element.find('.fc-event-title').after(time);
... any other code here ...
}

Categories