Adding defineTemplates() results in view with no scheduler

I’m having a problem with the view not displaying the scheduler when I add the following line to my controller index method:

[*]scheduler.BeforeInit.Add(“defineTemplates();”);

I have added a defineTemplates() function to my javascript file:

function defineTemplates() {
//**
//Override to add color css
//**
scheduler.templates.event_class = function (start, end, event) {

     // Get filter values
    var filterColorRange = $("#propertySelectForm #ColorRange").val();

    // Check filter values
    if (filterColorRange == "Reservation Status") {
        if (event.reservation_status == 'unconfirmed')
            return "unconfirmed_event";
        else if (event.reservation_status == 'confirmed')
            return "confirmed_event";
    }
    else if (filterColorRange == "Gender") {
        if (event.gender == 'male')
            return "gender_male_event";
        else if (event.gender == 'female')
            return "gender_female_event";
        else
            return "gender_not_set_event";
    }
    else {
        if (event.shadow_event)
            return "virtual_event";
    }
};

}

Looking at the markup for the view, the div class “dhx_cal_data” contains no tables when I use the scheduler.BeforeInit.Add(“defineTemplates();”); line.


In addition, the attached image has two screenshots of the scheduler controller on the view. The top image displays the scheduler when the controller is not calling scheduler.BeforeInit.Add(“defineTemplates();”);, and the bottom image is when the controller is calling the method.

I’m also getting an error in firebug:

Uncaught ReferenceError: defineTemplates is not defined

Hi,
scheduler initializes itself as soon as all required dom elements are ready, so make sure that your js function is available by that time. The easiest way is to add js file above DHXScheduler.Render() call

Thanks, Aliaksandr. I added a @Scripts.Render() before the Scheduler.Render() and it works as you described.