以编程方式更改Kendo Grid中的绑定复选框,而不保留其新值

时间:2015-10-17 20:30:11

标签: kendo-ui kendo-grid

我需要协助尝试以编程方式检查/取消选中kendo网格中的复选框。

我将此相关领域的部分Grids数据源作为......

     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规则和类来强制它,这使得它看起来像#34;脏,但当我更改复选框的值时,在保存时,它会回到原来的状态。

数据绑定到接收报告数据。所以我想我在论坛上看到我需要做一些像datasource.set(&#34; receivereport&#34;,false);也许同步?同步会触发,但它没有帮助,我必须正确调用该设置,因为控制台说它在一个未识别的物体上发射。

这里是真正的踢球者,我知道如何访问该复选框并将其渲染为假,但它会向右翻转到它所绑定的内容!它没有举行。除非我点击该单元格并单击复选框,否则它不会......

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

我在这里看了一下这个例子Disable/Enable the checkbox in kendo grid based on column Value,但它看起来有点不同而不是我需要的。

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

无论如何,任何帮助都会非常感激。感谢。

1 个答案:

答案 0 :(得分:0)

这可以使用&#34;更改&#34; dataSource的事件:

         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)
              }
            },

以下是完整示例: