Drag and Drop Fullcalendar

Asked

Viewed 78 times

0

The documentation of fullcalendar is well summarized and I’m having trouble coding Drag and Drop. Someone could shed some light on how to start this function?

eventDrop:function(event, delta, revertFunc) {
   alert('ok');
}

I’m still developing the code, but the above call does not run when I run the calendar.

  • Vanderlei put the code you already have and explain exactly what problem you’re having. Asking randomly like this is hard to give you an accurate answer. Be clearer on what you need.

1 answer

0

I don’t know if that’s your case, but I hope it helps. I use fullcalendar by primeng, in an Angular project. For the event in question I call a function:

(onEventDrop)="reschedule($event)"

And my job is:

    reschedule(event) {

      if ((addHours(event.event.start._d, 3).getTime() > addHours(new Date(), 1).getTime())) { //
        if (this.notHaveConflicts(addHours(event.event.start._d, 3), addHours(event.event.end._d, 3), event.event.id)) {
          // console.log('nao');

          this.event = event.event;
          this.event.startdb = this.dateToStringDB(addHours(event.event.start._d, 3));
          this.event.enddb = this.dateToStringDB(addHours(event.event.end._d, 3));
          this.event.status = 3;
          this.event.cancel_reason = result.reason;
          delete this.event.source;

          // console.log(this.event);

          this.toggle_events = this._eventsService.updateEvent(this.event).subscribe(
            response => {
              if (response.return) {
                // evento atualizado
              } else {
                // erro no banco/API
                event.revertFunc();
              }
            },
            err => {
              // erro no banco
              event.revertFunc();
            }
          );

          this.reRender();

        } else {
          // teve conflito
          event.revertFunc();
        }
      } else {
        event.revertFunc();
        this._toastrService.error(this._translateService.instant('Agenda.IntervalError'),
          this._translateService.instant('Error.Err'));
      }
    }

In this project, the event is between 2 people, so I check the schedules in the API, if they collide, call the function:

revertFunc();

and my event goes back to exactly where it was. The fullcalendar itself already guards the previous location to return, so in my case it was just call it that worked! = D

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.