How to hook event on next/prev button of Fullcalendar with GWT?

639 views Asked by At

Using https://gwtbootstrap3.github.io/gwtbootstrap3-demo/#fullcalendar

How do you

  • Hook and event on the next and previous button
  • Set background color to a specific date on the calendar
1

There are 1 answers

0
Adam On BEST ANSWER

The easiest way is to hook up on display viewRender event. As documentation states:

This callback will get triggered when the user changes the view, or when any of the date navigation methods are called.

Here is the code:

GeneralDisplay generalDisplay = new GeneralDisplay();
generalDisplay.setViewRenderCallback(new ViewRenderCallback() {
    @Override
    public void windowResize(JavaScriptObject view) {
    }

    @Override
    public void viewRender(JavaScriptObject view, Element element) {
        Window.alert("viewRender");
    }

    @Override
    public void viewDestroy(JavaScriptObject view, Element element) {
    }

    @Override
    public void dayRender(JavaScriptObject moment, Element tdElement) {
    }
});

CalendarConfig config = new CalendarConfig();
config.setGeneralDisplay(generalDisplay);

final FullCalendar calendar = new FullCalendar(Document.get().createUniqueId(), ViewOption.month, config, false);

To set background for specific date just use Background events:

Event backgroundEvent = new Event(Document.get().createUniqueId(), "");
backgroundEvent.setStart(new Date(1511136000000L));
backgroundEvent.setAllDay(true);
backgroundEvent.setRendering("background");
backgroundEvent.setBackgroundColor("red");
calendar.addEvent(backgroundEvent);