I have fullcalendar working fine loading data using json from a flatfile(s).
I would like to load each months data from that months file on clicking prev/next.
Using ajax? events: function( start, end, callback ) addEventSource - removeEventSource? other?
Allow that jQuery is still a work in progress for me.
UPDATE:
I have set:
viewDisplay: function(view) { var next = view.title; alert(next); },
which gives me Month Year on clicking next/prev
How to parse this to json-events.php
I tried [split next] events: "json-events.php?month=month",
nope...
This is not using php, but you can change the AJAX call in getCalData() to do it.
EventSource will be filled with the next data.
I hope this helps a little bit.
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'resourceMonth'
},
defaultView: 'resourceWeek',
eventSources: [ getCalData() ],
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
viewDisplay: function (view) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('addEventSource', getCalData());
$('#calendar').fullCalendar('rerenderEvents');
}
});
});
function getCalData() {
var source = [{}];
$.ajax({
async: false,
url: '/mysite/GetWeekData',
data: { myParam: $('#calendar').fullCalendar('getView').visStart },
success: function (data) {
$(data).each(function () {
source.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
});
});
},
error: function () {
alert('could not get the data');
},
});
return source;
}
fullcalendar by default send 2 additional parameters when getting events, params[:start], params[:end]
u can use them to return queried events between these 2 values
you can just add View Render property to configuration Object of fullcalendar
viewRender: function(view, element) {
//console.debug("View Changed: ",view.start, view.end);
// events = loadevents();
jQuery(nativeelement).fullCalendar('removeEvents');
jQuery(nativeelement).fullCalendar('addEventSource', events);
}
now you can load month by month.
This syntax for angular2
Related
I have added onclick event on the Fullcalender.js on the events. But when I am changing the calender view from Month to Week or Day that onclick event is not working anymore. Please help me how to fix this.
Here is my code for the first time after the page load, it working perfectly but after the change of view the click is not working:
<script>
$(document).ready(function () {
debugger;
$.ajax({
url: "/Appointment/GetAgendaList",
data: {userid:#Convert.ToInt32(Session["UserID"])},
dataType: "json",
type: "POST",
success: function (response) {
debugger;
//load all events
LoadEvents(response);
}
});
//Add click events on each Event link to get details
var clicks = 0;
$('td.fc-event-container a').on({
click: function (event) {
node = $(this);
clicks++;
if (clicks == 1) {
setTimeout(function () {
if (clicks == 1) {
$('#loderdiv').show();
var loadurl = $('input#hdneventdetailsurl').val();
var eventid = $(node).find('input.hdneve_id').val();
loadurl = loadurl + "/" + eventid;
$('#myagenda').load(loadurl, function () {
$('div#myagenda').modal('show');
$('#loderdiv').hide();
});
}
clicks = 0;
}, 300);
}
}
});
});
//Initialize the calender and add all events
function LoadEvents(data)
{
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '#DateTime.Now.ToString("yyyy-MM-dd")',
editable: true,
eventLimit: true, // allow "more" link when too many events
events:data
});
}
I am using fullcalendar with json feed, the code is as follows
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: {
url: '/EventInfo/GetEventsByEmployee',
cache: false,
lazyFetching:true,
type: 'POST',
data: {
empId: $('#eventownerId').val()
},
error: function () {
alert('there was an error while fetching events!');
},
},
dayClick: function (date, allDay, jsEvent, view) {
displayDayEvents(date, allDay, jsEvent, view);
},
eventRender: function (event, element) {
element.find('.fc-event-time').hide();
element.attr('title', event.tip);
}
});
Here I am passing selected value of drop down control through data field as "empId: $('#eventownerId').val()". It returns correct data at page load.
Now I want to reload the calendar data when user selects option from drop down list.
for this purpose I used following code
$('#eventownerId').change(function (e) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('refetchEvents');
});
But refetch calls the json method with old data (i.e. initial value of drop down control), even selected value of drop down has been changed.
How I can pass current value of drop down control and reload the fullcalendar?
I managed the problem by calling destroy of fullcalendar, as follows
$('#dropdownlistId').change(function (e) {
$('#calendar').fullCalendar('destroy');
RenderCalendar($(this).val());
});
and RenderCalendar() is
function RenderCalendar(eId) {
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: {
url: '/EventInfo/GetEventsByEmployee',
cache: true,
type: 'POST',
data: {
empId: eId
},
error: function () {
alert('there was an error while fetching events!');
},
},
dayClick: function (date, allDay, jsEvent, view) {
displayDayEvents(date, allDay, jsEvent, view);
},
eventRender: function (event, element) {
element.find('.fc-event-time').hide();
element.attr('title', event.tip);
}
});
}
Using this I managed the problem but not sure this is correct way of doing it. i.e. destroying and recreating the calendar. I am still searching for correct way
Have you tried get the id in a var and then do it like this?
var id = $('#eventownerId').val(); //outside
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: {
url: '/EventInfo/GetEventsByEmployee',
cache: false,
lazyFetching:true,
type: 'POST',
data: {
empId: id // var in here
},
error: function () {
alert('there was an error while fetching events!');
},
},
dayClick: function (date, allDay, jsEvent, view) {
displayDayEvents(date, allDay, jsEvent, view);
},
eventRender: function (event, element) {
element.find('.fc-event-time').hide();
element.attr('title', event.tip);
}
});
Another thing check if the ID is actually getting the diferent id from dropdown. Can you show the GetEventsByEmployee method? Cheers
I am integrating fullCalendar in my meteor application. fullCalendar expects a specific data format. I can create that data from my Collection. However the data is no longer reactive.
What is a way I can make the data I translated from my Collection to an Array "reactive"?
Thanks.
Client html:
<template name="carpool_calendar">
<div id="calendar"></div>
</template>
Client JS:
Template.carpool_calendar.rendered = function () {
//initialize the calendar in this template
$('#calendar').fullCalendar({
events: function(start, end, callback) {
var events = [];
var calendarEvents = Carpool_Events.find();
calendarEvents.forEach(function (carpool_event) {
events.push({
title: carpool_event.owner,
start: carpool_event.eventDate
});
console.log("Event owner " + ": " + carpool_event.owner);
});
callback(events);
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
weekends: false, // will hide Saturdays and Sundays
editable: true
});
};
Updated Client JS (This is not quite right yet. Its recreating the calendar on every data change...the page gets longer and longer with new calendar instances):
Template.carpool_calendar.rendered = function () {
Meteor.autorun(function() {
//initialize the calendar in this template
$('#calendar').fullCalendar({
events: function(start, end, callback) {
var events = [];
var calendarEvents = Carpool_Events.find();
calendarEvents.forEach(function (carpool_event) {
events.push({
title: carpool_event.owner,
start: carpool_event.eventDate
});
console.log("Event owner " + ": " + carpool_event.owner);
});
callback(events);
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
weekends: false, // will hide Saturdays and Sundays
editable: true
});
})};
Client JS Fully working "reactive" fullcalendar:
Template.carpool_calendar.rendered = function () {
//initialize the calendar in this template
$('#calendar').fullCalendar({
events: function(start, end, callback) {
var events = [];
var calendarEvents = Carpool_Events.find();
calendarEvents.forEach(function (carpool_event) {
events.push({
title: carpool_event.owner,
start: carpool_event.eventDate
});
console.log("Event owner " + ": " + carpool_event.owner);
});
callback(events);
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
weekends: false, // will hide Saturdays and Sundays
editable: true
});
Meteor.autorun(function() {
var calendarEvents = Carpool_Events.find();
$('#calendar').fullCalendar('refetchEvents');
});
};
Like TimDog said, you can't give the UI element a reactive array, and let it take care of the rest. But another option is you could use Meteor.autorun so when your collection changes, it can trigger a JS function to make an updated array, thereby making it somewhat reactive.
I'm not sure how to use this calendar exactly, but adding this into your client side code might help.
Meteor.autorun(function() {
calendarEvents = Carpool_Events.find();
$('#calendar').fullCalendar({
events: function(start, end, callback) {
var events = [];
calendarEvents.forEach(function (carpool_event) {
events.push({
title: carpool_event.owner,
start: carpool_event.eventDate
});
});
callback(events);
}
});
});
This is part of a bigger question regarding how to properly create UI components for Meteor that ensure reactive data contexts. It's a very good question and one that's been asked before.
The short answer is that there is no standardized framework yet -- like a Meteor.UI smart package. In the interim, however, your best bet is to hack the fullCalendar widget using the {{#each}} helper source as your guide. You'll want to pay attention to how data elements are labeled with Spark:
'each': function (data, options) {
var parentData = this;
if (data && data.length > 0)
return _.map(data, function(x, i) {
// infer a branch key from the data
var branch = (x._id || (typeof x === 'string' ? x : null) ||
Spark.UNIQUE_LABEL);
return Spark.labelBranch(branch, function() {
return options.fn(x);
});
}).join('');
else
return Spark.labelBranch(
'else',
function () {
return options.inverse(parentData);
});
},
I have inserted some new functions in my js but dayClick and eventClick don't work. The calendar is able to load properly though.
Any idea why the dayclick and eventclick in the following code is not working?
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: '',
right: 'agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
allDayDefault: false,
allDaySlot: false,
firstHour: 9,
defaultView: 'agendaWeek',
dayClick: function(date, allDay, jsEvent, view) {
calendar.fullCalendar('gotoDate', date);
},
eventClick: function(calEvent, jsEvent, view) {
window.location = "http://www.domain.com?start=" + calEvent.start;
},
select: function(start, end) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end
},
false // make the event "stick"
);
var startDateString = $.fullCalendar.formatDate(start, 'yyyy-MM-dd hh:mm');
var endDateString = $.fullCalendar.formatDate(end, 'yyyy-MM-dd hh:mm');
$.ajax({
type: 'POST',
url: '{url}ajaxpost/add',
data: {
startDate: startDateString,
endDate: endDateString,
eventTitle: title
},
dateType: 'json',
success: function (resp) {
calendar.fullCalendar('refetchEvents');
}
});
}
calendar.fullCalendar('unselect');
},
editable: true,
events: "{url}ajaxget/data",
});
});
You cannot use the "select" callback and the "dayClick" callback together as there is a conflict between the two. You can use datepicker to accomplish the gotoDate function to accomplish the same thing.
http://weblogs.asp.net/gunnarpeipman/archive/2010/02/02/linking-jqueryui-datepicker-and-fullcalendar.aspx
As for the eventClick Im not sure why it is not working, but it is easier to place the url in the database the call it in the events and just set it as the property "url: www.somesite.com/sdfjkiwe"
As a side note, It would probably wor better if you didn't use renderEvent to display your event. Try using the event function found here to use your ajax call within it.
http://arshaw.com/fullcalendar/docs/event_data/events_function/
How can i get notified when the user click on 'next' (arrow) ?
I'm using the calendar in month view and I want to load the next month data on demand.
Also, do smbdy has an example of consuming data from ASP.NET (AJAX call) ?
you can use the viewDisplay trigger (http://arshaw.com/fullcalendar/docs/display/viewDisplay/) but that gets called also when the calendar loads, or the user switches views.
it sounds like you'd want an events function instead:
http://arshaw.com/fullcalendar/docs/event_data/events_function/
for the asp.net thing, have you looked here?
http://weblogs.asp.net/gunnarpeipman/archive/2010/02/03/using-fullcalendar-jquery-component-with-asp-net-mvc.aspx
Your way of approaching is wrong. You may need to write an API which returns the list of calendar objects in JSON, and use the following options.
$('#calendar').fullCalendar({
events: '/myfeed.php'
});
Then, fullcalendar will automatically call /myfeed.php whenever it needs.
e.g. If a user clicks 'prev' or 'next' month button.
Here's the example URL fullcalendar will generate :
/myfeed.php?start=1262332800&end=1265011200&_=1263178646
For more information, please visit the following URL.
http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/
Here the viewDisplay function is called when the user clicks next/prev. Also, you can see that is is getting the next lot of data via AJAX.
I hope this helps :)
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'resourceMonth'
},
defaultView: 'resourceWeek',
eventSources: [ getCalData() ],
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
viewDisplay: function (view) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('addEventSource', getCalData());
$('#calendar').fullCalendar('rerenderEvents');
}
});
});
function getCalData() {
var source = [{}];
$.ajax({
async: false,
url: '/mysite/GetWeekData',
data: { myParam: $('#calendar').fullCalendar('getView').visStart },
success: function (data) {
$(data).each(function () {
source.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
});
});
},
error: function () {
alert('could not get the data');
},
});
return source;
}