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

How to display multiple events by having flexible row height? #25

Closed
Peterngkc opened this issue Aug 2, 2017 · 7 comments
Closed

How to display multiple events by having flexible row height? #25

Peterngkc opened this issue Aug 2, 2017 · 7 comments
Assignees

Comments

@Peterngkc
Copy link

Peterngkc commented Aug 2, 2017

I have managed to output multiple events on one day from my database. However, the height of each row in the Calendar does not adjust to the number of events.

Is there anyway to have the calendar adjust its row height automatically depending on the number of events, without using scroll?

@Peterngkc
Copy link
Author

Added these code to get a dynamic height for each row in the calendar. However, it is no too 'responsive' to the width of the browser.

$('#calendar').on('shown.calendar.calendario', function () {

        var elementHeight1 = $('.fc-row:nth-child(1) .fc-content').map(function () {
            return $(this).height();
        }).get();
        var maxHeight = Math.max.apply(null, elementHeight1);
        if (maxHeight > 0 & window.matchMedia('(min-width: 880px)').matches) {
            $('.fc-row:nth-child(1)').height(maxHeight + 10);
        }
        else if (window.matchMedia('(min-width: 880px)').matches) {
            var calendarHeight = 370;
            $('.fc-four-rows .fc-row:nth-child(1)').height(0.25 * calendarHeight);
            $('.fc-five-rows .fc-row:nth-child(1)').height(0.20 * calendarHeight);
            $('.fc-six-rows .fc-row:nth-child(1)').height(0.16 * calendarHeight);
        }

        var elementHeight2 = $('.fc-row:nth-child(2) .fc-content').map(function () {
            return $(this).height();
        }).get();
        var maxHeight = Math.max.apply(null, elementHeight2);
        if (maxHeight > 0 & window.matchMedia('(min-width: 880px)').matches) {
            $('.fc-row:nth-child(2)').height(maxHeight + 10);
        }
        else if (window.matchMedia('(min-width: 880px)').matches) {
            var calendarHeight = 370;
            $('.fc-four-rows .fc-row:nth-child(2)').height(0.25 * calendarHeight);
            $('.fc-five-rows .fc-row:nth-child(2)').height(0.20 * calendarHeight);
            $('.fc-six-rows .fc-row:nth-child(2)').height(0.16 * calendarHeight);
        }

        var elementHeight3 = $('.fc-row:nth-child(3) .fc-content').map(function () {
            return $(this).height();
        }).get();
        var maxHeight = Math.max.apply(null, elementHeight3);
        if (maxHeight > 0 & window.matchMedia('(min-width: 880px)').matches) {
            $('.fc-row:nth-child(3)').height(maxHeight + 10);
        }
        else if (window.matchMedia('(min-width: 880px)').matches) {
            var calendarHeight = 370;
            $('.fc-four-rows .fc-row:nth-child(3)').height(0.25 * calendarHeight);
            $('.fc-five-rows .fc-row:nth-child(3)').height(0.20 * calendarHeight);
            $('.fc-six-rows .fc-row:nth-child(3)').height(0.16 * calendarHeight);
        }

        var elementHeight4 = $('.fc-row:nth-child(4) .fc-content').map(function () {
            return $(this).height();
        }).get();
        var maxHeight = Math.max.apply(null, elementHeight3);
        if (maxHeight > 0 & window.matchMedia('(min-width: 880px)').matches) {
            $('.fc-row:nth-child(4)').height(maxHeight + 10);
        }
        else if (window.matchMedia('(min-width: 880px)').matches) {
            var calendarHeight = 370;
            $('.fc-four-rows .fc-row:nth-child(4)').height(0.25 * calendarHeight);
            $('.fc-five-rows .fc-row:nth-child(4)').height(0.20 * calendarHeight);
            $('.fc-six-rows .fc-row:nth-child(4)').height(0.16 * calendarHeight);
        }

        var elementHeight5 = $('.fc-row:nth-child(5) .fc-content').map(function () {
            return $(this).height();
        }).get();
        var maxHeight = Math.max.apply(null, elementHeight5);
        if (maxHeight > 0 & window.matchMedia('(min-width: 880px)').matches) {
            $('.fc-row:nth-child(5)').height(maxHeight + 10);
        }
        else if (window.matchMedia('(min-width: 880px)').matches) {
            var calendarHeight = 370;
            $('.fc-four-rows .fc-row:nth-child(5)').height(0.25 * calendarHeight);
            $('.fc-five-rows .fc-row:nth-child(5)').height(0.20 * calendarHeight);
            $('.fc-six-rows .fc-row:nth-child(5)').height(0.16 * calendarHeight);
        }

        var elementHeight6 = $('.fc-row:nth-child(6) .fc-content').map(function () {
            return $(this).height();
        }).get();
        var maxHeight = Math.max.apply(null, elementHeight6);
        if (maxHeight > 0 & window.matchMedia('(min-width: 880px)').matches) {
            $('.fc-row:nth-child(6)').height(maxHeight + 10);
        }
        else if (window.matchMedia('(min-width: 880px)').matches) {
            var calendarHeight = 370;
            $('.fc-four-rows .fc-row:nth-child(6)').height(0.25 * calendarHeight);
            $('.fc-five-rows .fc-row:nth-child(6)').height(0.20 * calendarHeight);
            $('.fc-six-rows .fc-row:nth-child(6)').height(0.16 * calendarHeight);
        }


    });

@deviprsd
Copy link
Collaborator

Why don't you just use a scroll, like a javascript custom scroll or css one.

@Peterngkc
Copy link
Author

There will be at least 8-15 events per day. Using a scroll will make it rather untidy.

By the way, the calendar appears first then followed by the data from the database. How do I load the data first?

@deviprsd
Copy link
Collaborator

https://github.com/CalendarioFX/Calendario/blob/master/index2.html#L114 like this, if you happen to load the events through ajax or whatever method you are using. You can initialize calendar after a successful ajax and likewise.

@Peterngkc
Copy link
Author

Peterngkc commented Aug 16, 2017

Can you guide me? I load the events using:

        $.get('/Calendar/CalendarJson', { name: 'content' }, function (data) {
            var obj = JSON.stringify(data);
            $('#calendar').calendario('setData', data, false);
        }, 'json');

@deviprsd
Copy link
Collaborator

How about you initialize the calendar when you have the events

$.get('/Calendar/CalendarJson', { name: 'content' }, function (data) {
    var obj = JSON.stringify(data);
    $( '#calendar' ).calendario({
        caldata : data, //events go here
        displayWeekAbbr : true,
        events: ['click', 'focus']
    });
}, 'json');

@Peterngkc
Copy link
Author

Thanks, it works!

@deviprsd deviprsd self-assigned this Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants