Available only in PRO Edition
This functionality is available in the Scheduler PRO version (Commercial (since October 6, 2021), Enterprise and Ultimate licenses) only.
As you have probably noticed at the very beginning of your work with the library, dhtmlxScheduler is a static object, i.e. only one instance of dhtmlxScheduler can exist on the page.
Now, for the PRO version, we should rephrase that statement and say: more than one instance of dhtmlxScheduler can exist on the page. You still have one default instance of scheduler, which can be accessed by the global scheduler object, but you can also create new scheduler objects.
To create a new instance of dhtmlxScheduler, use the Scheduler.getSchedulerInstance() method:
// Beware, 'Scheduler' in the command goes with the capital letter
const scheduler = Scheduler.getSchedulerInstance();
The method can take a configuration object as a parameter:
const scheduler = Scheduler.getSchedulerInstance({
plugins: {
recurring: true,
},
container: "scheduler_here",
config: {
hour_date: "%h:%i",
details_on_create: true
},
data: {
events: [
{ id:1, start_date: "2022-04-18 09:00", end_date: "2022-04-18 12:00",
text:"English lesson", subject: 'english' },
{ id:2, start_date: "2022-04-20 10:00", end_date: "2022-04-21 16:00",
text:"Math exam", subject: 'math' },
{ id:3, start_date: "2022-04-21 10:00", end_date: "2022-04-21 14:00",
text:"Science lesson", subject: 'science' },
{ id:4, start_date: "2022-04-23 16:00", end_date: "2022-04-23 17:00",
text:"English lesson", subject: 'english' },
{ id:5, start_date: "2022-04-22 09:00", end_date: "2022-04-22 17:00",
text:"Usual event" }
]
}
});
The config object can contain the following properties:
const scheduler = Scheduler.getSchedulerInstance({
events: {
onEventCreated: function(id, e){
var task = scheduler.getEvent(id);
task.owner = null;
return true;
},
onClick: function(id, e){
alert(scheduler.getEvent(id).text);
return true;
}
}
});
Note, that calling the Scheduler.getSchedulerInstance() method without parameters will return the scheduler object with default configuration settings. Therefore, you need to configure your new instance, initialize it and populate with data, as usual.
Let's take a simple example: 2 schedulers, one under another:
window.addEventListener("DOMContentLoaded", function(){
var scheduler1 = Scheduler.getSchedulerInstance();
scheduler1.init('scheduler_here',new Date(2019,5,30),"week");
scheduler1.load("/data/events")
var scheduler2 = Scheduler.getSchedulerInstance();
scheduler2.init('scheduler_here_2',new Date(2019,5,30),"month");
scheduler2.load("/data/events")
)};
<body>
<div id="scheduler_here" style="width:100%; height: 50%;"></div>
<div id="scheduler_here_2" style="width:100%; height: 50%;"></div>
</body>
Starting from version 6.0, the dhtmlxScheduler object has a destructor that can be used to dispose unnecessary instances of the Scheduler.
The destructor of the scheduler instance can be used as follows:
var myScheduler = Scheduler.getSchedulerInstance();
//destroying a scheduler instance
myScheduler.destructor();
The destructor will implement the following tasks:
Here is an example of using the destructor to dispose a scheduler instance while using the Angular framework:
@Component({selector: 'app-scheduler', template: `...`})
class MySchedulerComponent implements OnDestroy {
ngOnInit() {
this.$gantt = Scheduler.getSchedulerInstance();
// configure and init
}
ngOnDestroy() {
this.$scheduler.destructor();
this.$scheduler = null;
}
}
Calling the destructor of data processor will clear the dataProcessor instance and detach it from the scheduler. For example:
var scheduler = Scheduler.getSchedulerInstance();
var dp = new scheduler.DataProcessor("url");
dp.init(scheduler);
// destroys data processor and detaches it from the scheduler
dp.destructor();
If you use a package that does not allow creating multiple instances of the scheduler object (GPL or Commercial editions), calling the scheduler destructor will make the scheduler inaccessible until page reload.