Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fullCalendar adding a class to events

Tags:

fullcalendar

I am trying to select events on fullcalendar, based on user selection.

Example: if user selects class A, then all classes with the same ID should turn green (using applied className).

I am having trouble applying classes to the other events that I can successfully select by ID. I guess my issue is combining the event objects with jQuery objects.

sample code:

eventClick: function(event) {
  $(this).addClass("reg_selected");  //this works fine on selected event
  var selectedID = event.id
  alert(selectedID);                 //get event.ID, and use it to find similar ones.
  var similarEvents = $("#calendar").fullCalendar('clientEvents',selectedID).addClass("reg_selected");

the error I get is:

  addClass is not a function

I also tried this method of looping, and got the same error:

for (var i = 0; similarEvents.length > i ; i++){
    alert(similarEvents[i].title);
    similarEvents[i].className("reg_selected");
}

the alert() worked, but the className() generated the same error as above

like image 664
kneidels Avatar asked Mar 16 '13 22:03

kneidels


People also ask

How do I create a dynamic event in FullCalendar?

although it is not specified on the fullcalender site, it is necessary to assign a value to the "allday" parameter to be able to add new events dynamically. If you set this value to "false", it will not add the event to the AllDay row. If you do "true" it will add to the AllDay row. Show activity on this post.

How do I set events in FullCalendar?

Here is an example of how to specify an array of events: var calendar = new Calendar(calendarEl, { events: [ { title : 'event1', start : '2010-01-01' }, { title : 'event2', start : '2010-01-05', end : '2010-01-07' }, { title : 'event3', start : '2010-01-09T12:30:00', allDay : false // will make the time show } ] });

What is FullCalendar eventRender?

eventRender is a great way to attach effects to event elements, such as a Tooltip. js tooltip effect: var calendar = new Calendar(calendarEl, { events: [ { title: 'My Event', start: '2010-01-01', description: 'This is a cool event' } // more events here ], eventRender: function(info) { var tooltip = new Tooltip(info.

How do I select multiple dates in FullCalendar?

Detect when the user clicks on dates or times. Give the user the ability to select multiple dates or time slots with their mouse or touch device. Allows a user to highlight multiple days or timeslots by clicking and dragging.


2 Answers

This answer for a very similar situation, but when event classes are selected with round-trip to the event source for possible persistence in the db or checks.

Class name can be specified in the event object in the source as follows (start and end given for the context only):

[{
  ...
  "className": "selected-event",
  "start": '2017-05-01T08:30:00.0',
  "ends": '2017-05-01T09:00:00.0',
  ...
}, ...]

The idea is that user clicks the event; ajax call to select events goes to backend; onsuccess, frontend javascript does$calendar.fullCalendar('rerenderEvents'); and receives the event source with events' classes. The immediate child of .fc-event-container gets the specified class, in the example above - selected-event.

As a result, the selection can be persisted on the backend.

like image 185
Roman Susi Avatar answered Sep 28 '22 05:09

Roman Susi


clientEvents returns an array of matching objects. You need to iterate through the array (in your case similarEvents) and call addClass for each item

Update: There is also issues using an id to update multiple events, using a filter function instead is a better way to go.

eventClick: function(event) {
    var similarEvents = $("#calendar").fullCalendar('clientEvents', function(e) { return e.test === event.test });

    for (var i = 0; similarEvents.length > i ; i++){
            similarEvents[i].className = 'reg_selected';
            $('#calendar').fullCalendar('updateEvent', similarEvents[i]);
        }
},

See jsfiddle

like image 31
tocallaghan Avatar answered Sep 28 '22 05:09

tocallaghan