Page 1 of 1

Getting start and end dates from Fullcalendar

Posted: Wed Jun 12, 2024 3:27 am
by josejad

Hi there:

I need to get the first and last dates shown on the calendar.

When I shown the calendar with a custom template , I could get the dates with:

	var date_from =calendar.view.activeStart;
	var date_to= calendar.view.activeEnd;

But now I don't know how to do it. I've tried adding a console.log after this code in Server->Global->All Pages->Page_Head

echo <<<EOD
<script>
loadjs.ready("jquery", () => {
    $(document).on("calendar", function (e, args) {
        const BtnPlaniDiaria = {		
            BtnPlaniDiaria: {
                text: 'Enviar',
                click: function() {
                    alert('testing');				
                }
            }
        }; 
        args.options.customButtons = Object.assign(args.options.customButtons, BtnPlaniDiaria);
        console.log(args.options); // View all options
    });
});
</script>
EOD;

but I can't find activeStart or activeEnd

Any ideas?
ThanksĀ”


Re: Getting start and end dates from Fullcalendar

Posted: Wed Jun 12, 2024 10:18 am
by arbei

If you want to set calendar options, you may read View-Specific Options.


Re: Getting start and end dates from Fullcalendar

Posted: Wed Jun 12, 2024 3:12 pm
by josejad

Thanks, I've set some options the way you teach me in other thread.

But now I don't want to set any options. I want to read the first date shown and the last one.

i.e. you click several times the "< >" buttons in the fullcalendar, to navigate between dates, showing i.e. weeks, from monday to sunday, 2024/06/10 to 2024/06/16... click next, then show from 2024/06/17 to 2024/06/23...

Then I want to know the activeStart and activeEnd..

It can be read from the https://fullcalendar.io/docs/view-object, but I cant reach them "console.log(args.view);" shows "undefined"


Re: Getting start and end dates from Fullcalendar

Posted: Wed Jun 12, 2024 8:33 pm
by arbei

There is no such property as args.view. (If you want to set views, you can add args.options.views though, but you want to read.) You may read FullCalendar's docs on View Object:
This information about the current view is passed into nearly every handler.


Re: Getting start and end dates from Fullcalendar

Posted: Wed Jun 19, 2024 4:40 am
by josejad

Hi, the trick was using "currentCalendar.view.activeStart"

echo <<<EOD
<script>
loadjs.ready("jquery", () => {
    $(document).on("calendar", function (e, args) {
        const BtnPlaniDiaria = {		
            BtnPlaniDiaria: {
                text: 'Enviar',
                click: function() {
                    alert(currentCalendar.view.activeStart);				
                }
            }
        }; 
        args.options.customButtons = Object.assign(args.options.customButtons, BtnPlaniDiaria);
        console.log(args.options); // View all options
    });
});
</script>
EOD;