Loading data when already un-marshalled into an array.

I’m using a JSF query (via a4j:jsFunction) to get scheduling data (fired via onBeforeViewChange event). When the jsFunction returns I have the data in an array of objects that are the same structure as events. I was loading the data with:

for (var i = 0; i < events.length; i++) {

However, when I started to approach 1000 events in a month, the load was taking on the order of 30 seconds in Chrome and pretty much killed IE9. So after digging into the source I tried the following and it worked really well. The time when from 30 seconds to under 1 second.

scheduler._loading = true;
scheduler._not_render = true;
for (var i = 0; i < events.length; i++) {
scheduler._loading = false;
scheduler._not_render = false;

So my question, is this the right want to handle this? Am I missing anything? If there isn’t a way to bulk load from an array, may I suggest adding one.

Note: I’m very new to Javascript and DHTMLX so it’s quite possible I’m missing something big here.


The above code must be valid, but it is based on inner flags, and may be broken by future updates.

if “events” structure is an array of json object - it can loaded at once by using

scheduler.parse(events, "json");

Hi Stanslev,

scheduler.parse(events, “json”); doesn’t work for me. I think the issue is that the data has already been parsed into objects. I believe the scheduler.parse function is expecting date strings that it then parses into date objects but in my events, the start and end dates are already Date objects.

I understand this is using internal hooks and I’m hoping that you might consider adding a new API point where the user can pass already parsed events to be loaded. In my case using a4j:jsFunction, the return data structure from JSF gets unmarshalled automatically into objects, including date parsing.

Thanks for the reply, it at least confirmed that I wasn’t just missing something. I hope you will consider adding a new entry point to the API, but if not I can probably live with that risk that I might have to make changes with any new versions.


Sorry for misspelling your name in the last post. I need to change my contacts or make the font a bit bigger. :blush:

If you are loading data only in this way, do the next, after scheduler.init

scheduler.templates.xml_date=function(date){ return date; };
scheduler.parse(events, “json”);

First line will modify date parsing logic, so it will use date objects from incoming data

I tried your suggestion of changing the xml_date template, and it does work for loading the data. However, it breaks the minical extension. I get the following error:

Uncaught TypeError: Object 04/01/2013 00:00 has no method 'setDate' 

when clicking on a date in the mini calendar. :frowning:

Yep, I have missed that one, but you can restore original handler after loading, like

var temp = scheduler.templates.xml_date; scheduler.templates.xml_date = function(date){ return date; }; scheduler.parse(events, "json"); scheduler.templates.xml_date = temp; // restoring original handler


Thanks, that worked great. Sorry for the delayed reply. :smiley: