I want to add "refresh" handler on the resource store. I add a listener. In the event "this" refers to the ResourceStore. "source" is also the ResourceStore. How can I get access to the SchedulerPro instance?
Support Forum
Hey David,
The ProjectModel
does not directly provide access to the SchedulerPro
instance either. The design is such that stores can be shared across multiple components, hence they do not maintain a direct reference to any specific SchedulerPro
instance.
To access the SchedulerPro
instance, using the ref is the recommended approach. This ensures you are interacting with the correct instance, especially in applications where multiple schedulers might be using the same data stores.
Best regards,
Márcio
How to ask for help? Please read our Support Policy
It's the typical case of trying to have a too "nice" design. I agree that it sounds good that the instances are not available. on the stores, as they can be associated with multiple. However, I assume 99% of the people use only one instance. For them it'd be easier if the instance would be "just there". For every other event handler the instance can be easily accessed, for event handlers on the stores one needs "special" logic.
Hello,
Data level has no notion of UI.
And even out of the box there are multiple instances of resource/task/dependency/assignments stores.
UI makes clones and chains of the original stores.
If you need the Scheduler to react on certain custom data level occasion you should trigger events:
class MyResourceStore extends ResourceStore {
someMethod() {
this.trigger('myCustomEvent', { foo : 'Bar' });
}
}
const scheduler = new SchedulerPro({
project : {
listeners : {
resourceStore : {
myCustomEvent : () => {
scheduler.refreshRows();
}
}
}
},
...
});
// or
scheduler.on({
myCustomEvent : () => {
scheduler.refreshRows();
}
});
Best regards,
Arcady