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 pass dynamic JSON data for date highlight. #36

Open
ShahbazAhmad90 opened this issue Oct 27, 2016 · 4 comments
Open

How to pass dynamic JSON data for date highlight. #36

ShahbazAhmad90 opened this issue Oct 27, 2016 · 4 comments

Comments

@ShahbazAhmad90
Copy link

I am using this calendar , it is great , just stuck at a point where i want to pass dynamic JSON through a variable not through a file URL, not be able to do this ... can you please help.

@richardtallent
Copy link
Contributor

It appears there's been a pull request open since April that would allow loading from a local XML string. Not sure what the maintainer's plans are for improvements, but I'm in the same situation if I want to use this on an upcoming project.

The setMonthly() function needs to be split to separate the concerns of setting up the calendar for a given month, loading events from a resource, and adding events to the calendar view.

@richardtallent
Copy link
Contributor

I've created a pull request #41 that allows for initializing the calendar with a local JSON object or XML string.

@ka306575
Copy link

ka306575 commented Nov 30, 2017

Please provide example for initializing the calendar with a local JSON object without making Ajax call

@TonyDandelion
Copy link

hi,you can change the function addEvents in monthly.js to use dynamic JSON data for date highlight. such as below.

    function addEvents(month, year) {
        if(options.events) {
            // Prefer local events if provided
            addEventsFromString(options.events, month, year);
        } else {
            var remoteUrl = options.dataType === "xml" ? options.xmlUrl : options.jsonUrl;
            if(remoteUrl) {
                // Replace variables for month and year to load from dynamic sources
                var url = String(remoteUrl).replace("{month}", month).replace("{year}", year);
                + var data = remoteUrl
                + addEventsFromString(data, month, year);
                - $.get(url, {now: $.now()}, function(data) {
                -   addEventsFromString(data, month, year);
                - }, options.dataType).fail(function() {
                -     console.error("Monthly.js failed to import " + remoteUrl + ". Please check for the correct path and " + options.dataType + " syntax.");
                - });
            }
        }
    }

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

4 participants