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

API (for dynamically creating events) #12

Closed
x68507 opened this issue Dec 22, 2013 · 5 comments
Closed

API (for dynamically creating events) #12

x68507 opened this issue Dec 22, 2013 · 5 comments
Labels

Comments

@x68507
Copy link

x68507 commented Dec 22, 2013

Although the visual format is pretty good for jqmCalendar, unless you publish the APIs or a "how-to", this is almost useless as a dynamic calendar. There is no information about how to add/change an event and the read-me file is too small to even be considered somewhat useful.

@jwgmeligmeyling
Copy link
Owner

To create events dynamically, simply create an object in the following format, append it to the event array supplied and force the calendar to repaint (for instance by selecting another month).

{ "summary" : "Test event", "begin" : new Date(), "end" : new Date() }

Please note that the Date constructor takes some arguments that might fit your needs better than just returning the date/time at creation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

The whole library is about 250 sloc, so I think any additional information isn't too much of a pain to figure out yourself. If you do see any improvements for the API documentation / Readme file though, please make a merge request with your suggested changes.

@x68507
Copy link
Author

x68507 commented Dec 23, 2013

I can easily repaint the canvas simply using "$('#myCalendar').trigger('refresh');", but I'm having trouble trying to access the actual EVENTS array object. How can I request the events array in order to append to it?

@jwgmeligmeyling
Copy link
Owner

You can separate the array from the settings object like this:

// Create an array that will contain the events
var eventsArray = [];

// Dynamically add events to the array (this can be done later on as well)
eventsArray.push({ "summary" : "Test event", "begin" : new Date(), "end" : new Date() }); 

// Initialize the calendar
$("#myCalendar").jqmCalendar({
   events : eventsArray, // Point to the events array now
   months : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
   days : ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
   startOfWeek : 0
}); 

// Add another event
eventsArray.push({ "summary" : "Test event", "begin" : new Date(), "end" : new Date() }); 
// Trigger refresh
$('#myCalendar').trigger('refresh');

Edit Clarified a bit

@x68507
Copy link
Author

x68507 commented Dec 23, 2013

Perfect. I didn't have a global eventsArray in my code. After initializing this array, I am able to dynamically add events. Thanks!

@jwgmeligmeyling
Copy link
Owner

I have just changed the read me a bit : https://github.com/JWGmeligMeyling/jqm-calendar

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

No branches or pull requests

2 participants