출처1 : https://fullcalendar.io/docs

출처2 : http://growingdev.tistory.com/101


다 괜찮았는데, event를 등록해서 ajax로 가지고 오는데 보니까 start하고 end만 동적으로 변환이되더라.

나의 경우 추가적인 파라미터를 더 주고 있었는데, 

추가 파라미터가 변하지 않으니 약간 애먹었었다.


요지는 events 부분을 function으로 처리하는 것이다.


<script type="text/javascript">

    function searchEvents() {

        $('#sCalendar').fullCalendar('refetchEvents');

    }

 

    Number.prototype.padLeft = function(n, str) {

        return (this < 0 ? '-' : '') +

            Array(n - String(Math.abs(this)).length + 1).join(str || '0') + (Math.abs(this));

    }

 

    function TimestampToLocalDate(numberTimestamp) {

        var date = new Date(numberTimestamp);

        if (typeof(date) == "object")

            return date.getFullYear() + "-" + (date.getMonth() + 1).padLeft(2) + '-' + date.getDate().padLeft(2);

        else

            return "";

    }

 

    function getCalendarParam(start, end) {

        return {

            start: TimestampToLocalDate(start),

            end: TimestampToLocalDate(end),

            mType: ($("input[name=chkmType]:checked").map(function() {

                return this.value;

            }).get().join(',')),

            hType: ($("input[name=chkhType]:checked").map(function() {

                return this.value;

            }).get().join(','))

        };

    }

 

    $(function() {

 

        $('#sCalendar').fullCalendar({

            locale: 'ko',

            height: 700,

            eventLimit: 3,

            eventLimitText: "더보기",

            eventLimitClick: "popover",

            eventSources: [{

                events: function(start, end, timezone, callback) {

                    $.ajax({

                        url: '/api/worktable/specialday/calendar/target',

                        type: 'GET',

                        dataType: "json",

                        data: getCalendarParam(start, end),

                        error: function() {

                            alert('error!');

                        },

                        success: function(data) {

                            callback(data);

                        }

                    });

                },

            }],

            eventClick: function(event) {

                if (event.url) {

                    alert(event.url);

                    return false;

                }

            },

        });

    });

</script>





Posted by motolies
,