以编程方式更改 Kendo 网格中未保留其新值的绑定复选框

Programmatically changing a bound check box in Kendo Grid not holding its new value

我需要帮助以编程方式 check/uncheck kendo 网格中的复选框。

我有这个相关领域的部分网格数据源作为...

     receivereport: {
                        editable: true,
                        nullable: false,
                        required: false,
                        type: 'boolean',
                        validation: {
                            required: false
                        }
                    },

网格配置是...

$("#contactGrid").kendoGrid({
        dataSource: contactGridDS,
        navigatable: true,
        dataBound: mapContactTypes,
        editable: true,
        edit: function (input) {


        },  
        toolbar: ["save", "cancel"],
        pageable: false,
        columns: [
            { field: 'email', title: 'Email', hidden: false, attributes: { "class": 'contactCell_email' } },
            { field: 'receivereport', title: 'Receive Reports?', hidden: false, attributes: { "class": 'contactCell_receivereport' }, template: '<input type="checkbox" #= receivereport ? "checked=checked" : "" # value=""  disabled="disabled" ></input>' }
        ],
        //filterable: true,
        sortable: {
            mode: 'single',
            allowUnsort: false
        }
    });

为了简洁起见,我把其他一些不相关的代码删掉了,比如这里没有涉及的其他领域。

所以,我有一个电子邮件方法,其中包含一个可以使用的正则表达式,我想做的是,如果焦点在电子邮件字段之外,或者焦点不在电子邮件字段中,如果该电子邮件无效,则接收报告字段错误,但它没有注册脏编辑,我什至尝试通过附加一些 CSS 规则和 类 来强制它,这使它变得 "look" 脏,但是当我更改值时复选框在保存时会恢复到原来的状态。

数据绑定到receivereport数据。所以我想我在这里的论坛上读到我需要做一些像 datasource.set("receivereport", false); 这样的事情。也许同步? syncinc 触发但它没有帮助,我一定是错误地调用了集合,因为控制台说它在一个不明对象上触发。

这才是真正的问题所在,我知道如何访问该复选框并将其呈现为 false,但它会立即翻转回其绑定的状态!它没有举行。除非我单击该单元格并单击复选框,否则它不会保留...

...除非我可以在目标上模拟一个虚假的点击事件,作为复选框...

我看了这里的例子,Disable/Enable the checkbox in kendo grid based on column Value,但是好像有点不一样,不是我需要的。

底线 - 如果复选框是 true/checked,并且用户返回电子邮件字段并使其无效,我想自动取消选中该复选框,并禁用该复选框,直到用户使电子邮件再次有效。这也意味着空电子邮件意味着复选框必须为假且已禁用。

无论如何,我们将不胜感激任何帮助。谢谢

这可以使用数据源的 "change" 事件来完成:

         dataSource = new kendo.data.DataSource({
            change: function(e) {
              if (e.action == "itemchange" && e.field == "email") {
                //you can check the email value as well:
                //var model = e.items[0];

                e.items[0].set("receivereport", false)
              }
            },

完整示例如下: