Modifying resources dataSource dynamically

7 posts, 0 answers
  1. Andres
    Andres avatar
    31 posts
    Member since:
    May 2011

    Posted 18 Dec 2013 Link to this post

    Hi,

    I'm trying to change the resources dataSource dynamically, but the changes I am making are not being applied to the Scheduler. 

    I've created a scheduler like so:

    $("#scheduler").kendoScheduler
    ({
        date: new Date(),
        startTime: new Date("2013/11/27 07:00 AM"),
        endTime: new Date("2013/11/27 06:00 PM"),
        height: "600",
        selectable: true,
        views: [
            "day",
            { type: "workWeek", selected: true },
            "week",
            "month",
            "agenda"
        ],
     
        editable: {
            template: kendo.template($("#schedulerTemplate").html())
        },
        dataSource: _dataSourceDetailedAppointmentScheduler,
        edit: _api.onEditScheduler,
        cancel: _api.onCancelScheduler,
        save: _api.onSaveScheduler,
     
        resources: [
            {
                field: "CommertialRepresentativeId", // The field of the scheduler event which contains the resource identifier
                title: "Representante Comercial", // The label displayed in the scheduler edit form for this resource
                dataSource: [
                    {
                        text: "Representante 1", // Text of the resource instance
                        value: 1, // Identifier of the resource instance, use that value to assign an event to this instance.
                        color: "#ff0000" // Used as the background of events assigned to this resource.
                    },
                ],
                multiple: false // Indicate the this is a multiple instance resource
            }
        ]
     
    });
    And after another control is modified, I try to replace the resources dataSource, changing the color of events with a value of 1 in the field: "CommertialRepresentativeId" to green.

    _dataSourceDetailedAppointmentScheduler.read();
    var schedulerControl = $("#scheduler").data("kendoScheduler");
    //Construir
    var resourceDS = new kendo.data.DataSource(
        {
            data: [
                { text: "rep 1",
                    value: 1,
                    color: "#00ff00"
                }
            ]
        }
                            
    );
    resourceDS.read();
     
    schedulerControl.resources[0].dataSource = resourceDS;
    schedulerControl.view(schedulerControl.view().name);

    Can't seem to figure out why the scheduler will continue to display the events in the original color.

    I'd appreciate some help!
  2. Andres
    Andres avatar
    31 posts
    Member since:
    May 2011

    Posted 18 Dec 2013 Link to this post

    So far the only solution I've found is to modify the existing datasource in the following way:

    var resource = schedulerControl.resources[0].dataSource.at(0);
    schedulerControl.resources[0].dataSource.remove(resource);
     
    schedulerControl.resources[0].dataSource.add({
                        text: "Rep 1",
                        value: 1,
                        color: "#00ff00"
                    });
    Which doesn't seem to be very clean. Could you please point me in the right direction?
  3. Kendo UI is VS 2017 Ready
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 19 Dec 2013 Link to this post

    Hi Andres,

    Basically modifying the scheduler resources after it's initialization is not supported out of the boxa and custom solution would be required. I would suggest to destroy the widget and re-initialize it with the new resources as current solution can lead to unexpected behavior. 

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Dave
    Dave avatar
    3 posts
    Member since:
    Mar 2011

    Posted 24 Sep 2015 in reply to Vladimir Iliev Link to this post

    Vladimir Iliev said:Hi Andres,

    Basically modifying the scheduler resources after it's initialization is not supported out of the boxa and custom solution would be required. I would suggest to destroy the widget and re-initialize it with the new resources as current solution can lead to unexpected behavior. 

    Does the latest version of the scheduler support dynamic resources, or Is this answer still correct? 

     

  6. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 25 Sep 2015 Link to this post

    Hello Darin,

    This is still the recommended approach, although it's possible to achieve it without destroying the widget using custom code (example here). 

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. Su C
    Su C avatar
    3 posts
    Member since:
    Feb 2016

    Posted 04 Mar Link to this post

    I am looking for something in similar lines but I want Attendees, Projects added in my CustomEditor everything else works but these newly added fields. The data for these 2 fields will come from a different dataSources. How do I achieve it?
  8. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 08 Mar Link to this post

    Hello Sujatha,

    As your last question is not related to the current thread could you please open a new support ticket and elaborate more on what exactly is not working when you add the new resources? Also please provide current Scheduler and it's editor configuration that you are using. This would help us advice you better how to proceed.

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready