'Putting an icon on FullCalendar's header

I put a CustomButton on FullCalendar's header but i need to put an font-awesome icon.

           customButtons: {
                btnBloquearAgenda: {
                    icon: 'fa fa-lock',
                    click: function() {
                        alert('clicked the custom button!');
                    }
                }
            },

            header: {
                left: 'prev,next',
                center: 'title',
                right: 'btnBloquearAgenda agendaDay,agendaWeek,month'
            },

The button is showing "Undefined".



Solution 1:[1]

The icon value is appended to 'fc-icon-' and added as a class to the button's span element, i.e.

            btnBloquearAgenda: {
                icon: 'fa fa-lock',
                click: function() {
                    alert('clicked the custom button!');
                }
            }

Would result in

<button type="button" class="fc-btnBloquearAgenda-button fc-button fc-state-default fc-corner-right">
<span class="fc-icon fc-icon-fa fa-lock"></span>
</button>

My work around was to just add an extra "fa" to the icon value

       customButtons: {
            btnBloquearAgenda: {
                icon: 'fa fa fa-lock',
                click: function() {
                    alert('clicked the custom button!');
                }
            }
        },

        header: {
            left: 'prev,next',
            center: 'title',
            right: 'btnBloquearAgenda agendaDay,agendaWeek,month'
        },

Result:

<button type="button" class="fc-btnBloquearAgenda-button fc-button fc-state-default fc-corner-right">
<span class="fc-icon fc-icon-fa fa fa-lock"></span>
</button>

Solution 2:[2]

Simple, just use some jquery to replace the buttontext.

$(".fc-today-button").html('<i class="fa fa-calendar"></i>');

Solution 3:[3]

I used @user3776999's answer it worked in version 5. But when calendar rerendered, icons duplicated one by one. To fix duplication add this script tag before your js.

<script>
   window.FontAwesomeConfig = { autoReplaceSvg: 'nest' }
</script>

https://github.com/fullcalendar/fullcalendar/issues/5544

Solution 4:[4]

to put the icon on FullCalendar's header without changing the code, try it with css,

put this one in diplay:

 viewDisplay   : function(view) {
     $(".fc-button-month").find(".fc-button-content").addClass("icocon");
 },

CSS

.icocon:before{
  font-family: "FontAwesome";  
  content: "\f133\00a0";
  color: #fff;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3776999
Solution 2 Sitsol
Solution 3 Nadir Hashimov
Solution 4 Anthony Kal