How can i set dependencies between event after data load in scheduler pro in bryntum?

89 views Asked by At

In Bryntum Scheduler Pro, in project object i load data by a url then i set dependencies between event by dependency_dict(which i pass from my backend) i try this code, but it show error like TypeError: scheduler.dependencies.addDependency is not a function, How can i set dependency between event after load data?

project: {
      transport: {
           load: {
                url: path,
           }
      },
      listeners: {
         load: function (project) {
            var response = project && project.response;
            var dependency_dict = response.dependencies.rows;

            if (dependency_dict) {
                    dependency_dict.forEach(function (dependency) {
              scheduler.dependencies.addDependency(dependency.fromEvent,dependency.toEvent);
           });
         }
      },
     },

     autoLoad: true,
     resourceStore: {
         modelClass: ResourceModel
     },
     eventStore: {
          modelClass: EventModel,
     },
   }

i also try this

var dependency_dict = response.dependencies.rows;  
if (dependency_dict) {
    dependency_dict.forEach(function (dependency) {
    project.dependencyStore.add(dependency);
}}

give me same error TypeError

my backend code : https://codefile.io/f/lXVaNcJZ4z my scheduler pro code : https://codefile.io/f/OZFfMIHQ3H

1

There are 1 answers

0
Tasnim Ahmed Auntik On

It's giving this error because inside of the config the scheduler is not available.

Try listening to load with https://bryntum.com/products/schedulerpro/docs/api/Core/helper/EventHelper#function-on-static on method

scheduler.project.on('load', () => { /* your listener code */ });

Or you could also do it in the config like the following

        listeners : {
            load(props) {
                const { source : project, response } = props;
                var dependency_dict = response.dependencies.rows;

                if (dependency_dict) {
                    dependency_dict.forEach(function (dependency) {
                        project.dependencyStore.add({ from : dependency.fromEvent, to : dependency.toEvent })
                    });
                };
            }
        }

Here is a codepen link so you can play with it https://codepen.io/dv-auntik/pen/poYvaPe?editors=0011

Docs: project.dependencyStore.add

By the way, May I know why you're adding the dependencies on load? it should be done automatically.

We have online demos with dependencies https://bryntum.com/products/schedulerpro/examples/dependencies/

And here is a dependencies demo with nested events https://bryntum.com/products/schedulerpro/examples/nested-events-dependencies/