We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Change resources in code

Hi,

I am trying to use ejSchedule to display events for multiple resources. This works fine as long as the resource data is static (in my case loaded via DataManager). 

Now I would like to enable the user to select what resources to display as opposed to displaying all resources. Is there a way to "refresh" the schedule view and take new resource data into account?

Br,
JensBo

1 Reply

KK Karthigeyan Krishnamurthi Syncfusion Team February 12, 2016 01:08 PM UTC

Hi JensBo,

Thanks for contacting Syncfusion support.

We have prepared a sample for your requirement “Need to dynamically display the resources based on user selection“ and that can be downloaded from the following location,
http://www.syncfusion.com/downloads/support/forum/121950/ze/ScheduleCRUDJS943958963

In the above sample we have initially displayed all the resources and their corresponding datum. If the user uncheck/check the particular resource, the respective resource will be removed/added in the schedule control. Kindly refer to the following code example that we have used in the above sample.
<Code>

function onChange(args) { // this function will be called when the resource is checked/unchecked

        var schObj = $("#Schedule1").data("ejSchedule");

        dataManager2 = ej.DataManager({

            url: '@Url.Action("owner","Home")',

            crossDomain: true

        });       

        dataManager2.adaptor = new ej.UrlAdaptor();

        var ds = dataManager2.executeQuery(new ej.Query());

        ds.done(function (e) {                  

            var resourceObject = ej.DataManager(e.result).executeLocal(ej.Query().where("resText", ej.FilterOperators.equal, args.model.text)); // here we will filter particular resource that is checked/unchecked

            if (args.isChecked)

                changeClick(resourceObject);

            else

                removeClick(resourceObject);

        });

       

    }

function changeClick(args) { // this function will be called when the resourse is checked

        var schObj = $("#Schedule1").data("ejSchedule");

        schObj.model.resources[0].resourceSettings.dataSource.push(args[0]); // here we are dynamically adding the checked resource

        var resVal = schObj.model.resources[0].resourceSettings.dataSource;

        var dataManager1 = ej.DataManager({

            url: '@Url.Action("GetData","Home")',

            //  url:"/Home/GetData",

            crudUrl: '@Url.Action("Batch", "Home")',

            crossDomain: true

        });


         ------------

         ------------

    }

     function removeClick(value) { // this function will be called when the resourse is un-checked

                var schObj = $("#Schedule1").data("ejSchedule");

                ej.DataManager(schObj.model.resources[0].resourceSettings.dataSource).remove("resId", value[0].resId); // here we are dynamically removing the unchecked resource

                var resVal = schObj.model.resources[0].resourceSettings.dataSource;

                $("#Schedule1").ejSchedule({

                    resources: [{

                        field: "OwnerId",

                        title: "Owner",

                        name: "Owners", allowMultiple: true,

                        resourceSettings: {

                            dataSource: resVal,

                            text: "resText", id: "resId", color: "rescolor"

                        }

                    }],

                });

            }
</Code>

Regards,
Karthigeyan


Loader.
Live Chat Icon For mobile
Up arrow icon