Kendo UI Web Scheduler - 动态修改资源数据源

Posted

技术标签:

【中文标题】Kendo UI Web Scheduler - 动态修改资源数据源【英文标题】:Kendo UI Web Scheduler - Modifying resources dataSource dynamically 【发布时间】:2014-01-07 07:10:08 【问题描述】:

我正在尝试动态更改资源数据源,但我所做的更改并未应用于调度程序。

我已经创建了一个这样的调度程序:

$("#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
        
    ]

);

在修改另一个控件后,我尝试替换资源数据源,将字段中值为 1 的事件颜色更改为:“CommertialRepresentativeId”为绿色。

_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);

似乎无法弄清楚为什么调度程序会继续以原始颜色显示事件。

我将不胜感激!

【问题讨论】:

【参考方案1】:

您应该使用resource.setDatasource 或resource.dataSource.data() 来更新配置:

var data = [ text: "rep 1", value: 1, color: "#00ff00" ];
schedulerControl.resources[0].dataSource.data(data);

如果您不想替换所有数据而只想更改一项,这也应该可以:

// id if you have one, otherwise dataSource.at(index) if you know the index
var existingItem = schedulerControl.resources[0].dataSource.get(id);
existingItem.set("color", "#00ff00");

【讨论】:

在删除最初包含的元素后,我最终这样做了:schedulerControl.resources[0].dataSource.add(text: "Rep 1", value: 1, color: "#00ff00"); 是否等效? @gaguevaras 如果您只想更改一项,那将起作用;如果您只想对某个项目进行小幅更改,我还编辑了另一个想法的答案【参考方案2】:

更改资源不会自动更新 UI。因此,您将需要手动刷新它。这可以通过调度程序视图方法选择当前视图来实现。

http://docs.telerik.com/kendo-ui/api/javascript/ui/scheduler#methods-view

scheduler.view("month");

【讨论】:

【参考方案3】:

大家可以查看以下完整的演示来编辑资源和刷新 UI:

Scheduler: Resources editing using Grid nested inside custom edit template

【讨论】:

以上是关于Kendo UI Web Scheduler - 动态修改资源数据源的主要内容,如果未能解决你的问题,请参考以下文章

Kendo UI Scheduler:如何创建自定义模板

Kendo UI Scheduler:自定义视图和编辑行为

我想在 Header 更改 Kendo ui Scheduler 的日期格式

Kendo UI Scheduler - MVVM 设置日期

在 Kendo UI Scheduler 上响应更改视图

Kendo UI (Scheduler) - 为每个事件添加唯一的 css 类