Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customDayRenderer Append other day's data #244

Open
BookHsu opened this issue Mar 15, 2019 · 0 comments
Open

customDayRenderer Append other day's data #244

BookHsu opened this issue Mar 15, 2019 · 0 comments

Comments

@BookHsu
Copy link

BookHsu commented Mar 15, 2019

I use this package to create a calendar.
I need make like Full example.
But I need to add the date of the lunar calendar.
Like this:
圖片

I find some problems between this.
When I was append text in customDayRenderer function.
then tooltip was no show.
Here's my code:

 $('#calendar').calendar({
                language: 'zh-TW',
                customDayRenderer: function (ele, date) {
                    var y = moment(date).format('YYYY');
                    var m = moment(date).format('M');
                    var d = moment(date).format('D');
                    var lunaData = window.LunarCalendar.solarToLunar(y, m, d);
                    var displayText = lunaData.lunarDay == 1 ? lunaData.lunarMonthName : lunaData.lunarDayName;
                    //節日 修改 packages/lunadatepicker/LunarCalendar.js
                    if (lunaData.lunarFestival) {
                        displayText = lunaData.lunarFestival
                    }
                    if (lunaData.solarFestival) {
                        displayText = lunaData.solarFestival
                    }
                    var _html = '<br /><span>' + displayText + '</span>';
                    $(ele).append(_html);
                    var _weekDay = date.getDay();
                    if (_weekDay == 0 || _weekDay == 6) {
                        $(ele).parent().addClass('vacationDay')
                    }


                },
                customDataSourceRenderer: function (ele, date, events) {                   
                    ele.parent().addClass('testtt')
                    console.log(ele);
                },
                enableContextMenu: true,
                enableRangeSelection: true,
                style: 'custom',
                contextMenuItems: [
                    {
                        text: 'Update',
                        click: editEvent
                    },
                    {
                        text: 'Delete',
                        click: deleteEvent
                    }
                ],
                mouseOnDay: function (e) {                   
                    if (e.events.length > 0) {
                        var content = '';

                        for (var i in e.events) {
                            content += '<div class="event-tooltip-content">'
                                + '<div class="event-name" style="color:' + e.events[i].color + '">' + e.events[i].name + '</div>'
                                + '<div class="event-location">' + e.events[i].location + '</div>'
                                + '</div>';
                        }

                        $(e.element).popover({
                            trigger: 'manual',
                            container: 'body',
                            html: true,
                            content: content
                        });

                        $(e.element).popover('show');
                    }
                },
                mouseOutDay: function (e) {                 
                    if (e.events.length > 0) {
                        $(e.element).popover('hide');
                    }
                },
                dayContextMenu: function (e) {                  
                    $(e.element).popover('hide');
                }
                

            });


            function editEvent(event) {
                $('#event-modal input[name="event-index"]').val(event ? event.id : '');
                $('#event-modal input[name="event-name"]').val(event ? event.name : '');
                $('#event-modal input[name="event-location"]').val(event ? event.location : '');
                $('#event-modal input[name="event-start-date"]').datepicker('update', event ? event.startDate : '');
                $('#event-modal input[name="event-end-date"]').datepicker('update', event ? event.endDate : '');
                $('#event-modal').modal();
            }

            function deleteEvent(event) {
                var dataSource = $('#calendar').data('calendar').getDataSource();

                for (var i in dataSource) {
                    if (dataSource[i].id == event.id) {
                        dataSource.splice(i, 1);
                        break;
                    }
                }

                $('#calendar').data('calendar').getCustomDataSourceRenderer(dataSource);
            }

            function saveEvent() {
                var event = {
                    id: $('#event-modal input[name="event-index"]').val(),
                    name: $('#event-modal input[name="event-name"]').val(),
                    location: $('#event-modal input[name="event-location"]').val(),
                    startDate: $('#event-modal input[name="event-start-date"]').datepicker('getDate'),
                    endDate: $('#event-modal input[name="event-end-date"]').datepicker('getDate')
                }

                var dataSource = $('#calendar').data('calendar').getDataSource();

                if (event.id) {
                    for (var i in dataSource) {
                        if (dataSource[i].id == event.id) {
                            dataSource[i].name = event.name;
                            dataSource[i].location = event.location;
                            dataSource[i].startDate = event.startDate;
                            dataSource[i].endDate = event.endDate;
                        }
                    }
                }
                else {
                    var newId = 0;
                    for (var i in dataSource) {
                        if (dataSource[i].id > newId) {
                            newId = dataSource[i].id;
                        }
                    }

                    newId++;
                    event.id = newId;

                    dataSource.push(event);
                }

                $('#calendar').data('calendar').setDataSource(dataSource);
                $('#event-modal').modal('hide');
            }
 

Finally, the result of my debugging.
In bootstrap-year-calendar.js
_renderBody function

圖片
I was append this code
cellContent.data('daynum',currentDate.getDate());
And in _renderDataSource function about in line 330
圖片
Originally using $(ele).text()
I replace to $(this).data('daynum')

In _getDate function

圖片

I replace too.

It is recommended to modify these places to be so.
This can be added to the custom text.

My English is not very good, please forgive me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant