Search code examples
fullcalendardouble-clickfullcalendar-4

How to get date where was background event double clicked in Fullcalendar v4?


I have background events in my Fullcalendar, I use timeline view. I added a doubleclick trigger to handle this action, but I need to get date, where was doubleclick done.

For example, if user clicks on highlighted square, it should fire "6th of November was double clicked". (greenline is background event).

enter image description here

eventRender: function(info) {
  $(info.el).on('dblclick', function() {
    // I need to somehow get clicked date here
    alert('XYZ was double clicked!');
  });
});

Is here a way how to get the clicked day?


Solution

  • I made the solution up. It is little bit dirty, but it works.

    1. I am calculating with mouse click coordinates
    2. get the width of day column
    3. calculate order of the clicked column
    4. by the order of clicked column I get the same column in the header
    5. I get the date from data-date attribute from the column in header

    .

    $(info.el).on('dblclick', function(event) {
        // get the element of the whole row
        var element = $(this).parent().offset();
    
        // get the x position of cursor
        var x = event.pageX - element.left;
    
        // get the width of column, dynamically calculated because width of viewport can be changed
        var width = $('.fc-head .fc-time-area th.fc-widget-header').outerWidth() - 1;
    
        // order number of clicked column
        var number = Math.ceil(x / width);
    
        // now we have a date of clicked date (despite we clicked background event)
        alert($('.fc-head .fc-time-area th.fc-widget-header:nth-of-type(' + number + ')').data('date'));
    });
    

    Maybe it helps somebody. Just notice, this solution counts with background events - these events are clicked.