views:

67

answers:

1

Hi Friends
Here is a code of full calendar i am using

$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaWeek,agendaDay'
},
editable: true,
events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
},
{
title: 'Long Event',
start: new Date(y, m, d-5),
end: new Date(y, m, d-2)
}
]
});
});

what i need is i am having a "a href" tag in the page while i click on that link,i need to add following data to event of the calendar and the event should be became like this

events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
},
{
title: 'Meet Thomas Antony',
start: new Date(y, m, 1),
},
{
title: 'Meet Mathew',
start: new Date(y, m, 1),
},
{
title: 'Long Event',
start: new Date(y, m, d-5),
end: new Date(y, m, d-2)
}
]

which means

{
title: 'Meet Thomas Antony',
start: new Date(y, m, 1),
},
{
title: 'Meet Mathew',
start: new Date(y, m, 1),
},

should be added to events on time of clicking a link tag, how can i do that?

+1  A: 

There's a renderEvent method in fullCalendar for this:

$('#calendar').fullCalendar('renderEvent', {
  title: 'Meet Thomas Antony',
  start: new Date(y, m, 1)
}, true).fullCalendar('addEvent', {
  title: 'Meet Mathew',
  start: new Date(y, m, 1)
}, true);

In a full example you'd be looping though a collection, but you get the idea, just call .fullCalendar('renderEvent', eventObject, true). For a full event object property listing, look here. The last parameter is optional, depending of if you refresh the event data source later...if you want it to say in that case, set it to true, otherwise you can leave it off.

Nick Craver
I Used the following code but it not working $(".ma").click(function () { $('#calendar').fullCalendar('addEvent', { title: 'Meet Thomas Antony', start: new Date(y, m, 1)}) });
Alex Mathew
@Alex - Apologies I haven't used this in a few versions (demo page was using 1.2), check the updated answer, the API changed a bit to `renderEvent` instead now.
Nick Craver
what about hiding the added events???any guess???
Alex Mathew
@Alex - you want to add them, then hide them?
Nick Craver
yes.....do we have any option for that, like when i click link ones,show them,and if i click one more hide them
Alex Mathew
@Alex - The best way to do that would be to give them a CSS class by specifying `className` on the event object, for example: `{ title: 'Meet Mathew', start: new Date(y, m, 1), className: 'meeting' }` then in those buttons, `$(".meeting").hide();` and `$(".meeting").show()` to show/hide those events.
Nick Craver