Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit fullcalendar event content

I am succeed in embedding the fullcalendar control in my asp.net mvc application. it is running perfect. But I want to edit existing event, what I have to do?

Edited: ok I have done with successfully Edit event in fullcalender control. but after edit the event, it assumes it as new event and rather replace another event it shows me one more event. and if i refreshes page, then it shows properly. So I think after I edit the event, some how i want to render / call again / refresh page.

Here is the code:

  $(document).ready(function() {
      var date = new Date();
      var d = date.getDate();
      var m = date.getMonth();
      var y = date.getFullYear();
      var officerid = document.getElementById('officerid').value;
      url = "/TasksToOfficer/Calender/" + officerid;


      var calendar = $('#calendar').fullCalendar({
          header: {
              left: 'prev,next today',
              center: 'title',
              right: 'month,agendaWeek,agendaDay',
              border: 0
          },
         eventClick: function(calEvent, jsEvent, view) {

              var title = prompt('Event Title:', calEvent.title, { buttons: { Ok: true, Cancel: false} });

              if (title) {
                  var st = calEvent.start;
                  var ed = calEvent.end;
                  var aldy = calEvent.allDay;
                  var dt = calEvent.date;
                  var iden = calEvent.id;

                  calendar.fullCalendar('renderEvent',
                                           {
                                               title: title,
                                               start: st,
                                               end: ed,
                                               allDay: aldy
                                           },
                                           true);


                  var date = new Date(st);
                  var NextMonth = date.getMonth() + 1;
                  var dateString = (date.getDate()) + '/' + NextMonth + '/' + date.getFullYear();



                  if (officerid) {
                      $.ajax(
                                                    {

                                                        type: "POST",
                                                        url: "/TasksToOfficer/Create",
                                                        data: "officerid=" + officerid + "&description=" + title + "&date=" + dateString + "&IsForUpdate=true&EventId=" + iden,
                                                        success: function(result) {

                                                            if (result.success) $("#feedback input").attr("value", ""); // clear all the input fields on success

                                                        },
                                                        error: function(req, status, error) {

                                                        }
                                                    });


                  }
              }

          }

              ,

          selectable: true,
          selectHelper: true,
          select: function(start, end, allDay) {
              var title = prompt('Event Title:', { buttons: { Ok: true, Cancel: false }

              });
              if (title) {
                  calendar.fullCalendar('renderEvent',
                                                                 {
                                                                     title: title,
                                                                     start: start,
                                                                     end: end,
                                                                     allDay: allDay
                                                                 },
                                              false); // This is false , because do not show same event on same date after render from server side.
                  var date = new Date(start);

                  var NextMonth = date.getMonth() + 1; // Reason: it is bacause of month array it starts from 0

                  var dateString = (date.getDate()) + '/' + NextMonth + '/' + date.getFullYear();

                  if (officerid) {
                      $.ajax(
                                                                    {

                                                                        type: "POST",
                                                                        url: "/TasksToOfficer/Create",
                                                                        data: "officerid=" + officerid + "&description=" + title + "&date=" + dateString + "&IsForUpdate=false",
                                                                        success: function(result) {

                                                                            if (result.success) $("#feedback input").attr("value", ""); // clear all the input fields on success
                                                                            //$("#feedback_status").slideDown(250).text(result.message); // show status message with animation
                                                                        },
                                                                        error: function(req, status, error) {

                                                                        }
                                                                    });
                  }
              }
              calendar.fullCalendar('unselect');
          },
          editable: true,
          lazyFetching: true,
          events: url //this will call the action from controller and show the saved events in db, the result of the action should be in proper formate.
      });
  });

I tried here with refetchEvent, renderEvents for call back , but not worked. Is here any other issue?

like image 914
Red Swan Avatar asked Dec 09 '10 07:12

Red Swan


People also ask

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 } ] });

How do I change the date on FullCalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.


1 Answers

Instead of calling renderEvent you will have to call updateEvent when you change one. Also notice that you have to provide the "real" calendar event to updateEvent, not one that you make up. So your code should go like this:

eventClick: function(calEvent, jsEvent, view) {
          var title = prompt('Event Title:', calEvent.title, { buttons: { Ok: true, Cancel: false} });

          if (title){
              calEvent.title = title;
              calendar.fullCalendar('updateEvent',calEvent);
          }
}
like image 65
Ryley Avatar answered Oct 03 '22 17:10

Ryley