search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Is it possible that the daypilot emitted javascript executes after page load?

Asked by DG
7 years ago.

The control tried to write some javascript on my page, something like this:

<script type='text/javascript'>
/* DayPilot Pro for ASP.NET MVC: 7.4.5587.1 */
var v = new DayPilot.Scheduler('dpScheduler');
Uncaught ReferenceError: DayPilot is not defined
v.allowMultiSelect = true;
v.api = 1;
...
...
</script>

In my application, I load all the resources/javascript later. So this gives me error "DayPilot is not defined".
Cannot all this script be wrapped in the onpageload function, so that my daypilot.js file is available when this code tried to execute?

Thanks.

Answer posted by Dan Letecky [DayPilot]
7 years ago.

You can initialize it using the JavaScript API directly instead of calling the @Html.DayPilotScheduler() helper.

Example:

function initScheduler() {
  var dps = new DayPilot.Scheduler('dpScheduler');  // assumes <div id="dpScheduler"></div> placeholder in the page
  dps.allowMultiSelect = true; 
  dps.api = 1; 
  // set other properties here, they usually have the same name as in DayPilotSchedulerConfig
  // see also http://api.daypilot.org/daypilot-scheduler-properties/
  // ...
  dps.init();
}
Comment posted by DG
7 years ago.

OK. I'll try that.

But I think there should be a way to handle this using that MVC helper method only, instead of writing my own custom javascript. Why would I use DayPilot MVC then?

Probably just a feature request I'm talking about. :-)

Comment posted by Dan Letecky [DayPilot]
7 years ago.

I could add an option to load daypilot.js asynchronously using the Html helper but that would mean the loading would be handled by the helper and not your code. Would that work for you?

Comment posted by DG
7 years ago.

Probably not.

I'm trying to initialize the scheduler using the javascript api as you suggested. But now I've come across another problem, which I'll first try to work around before asking you. :-)

Is there any downside of initializing the scheduler after pageLoad, and that too only optionally?

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.