动态应用Jqgrid必需属性

Roh*_*ner 4 javascript jquery jquery-ui jqgrid jqgrid-asp.net

在Jqgrid中,您将必需的属性应用于任何给定的字段,如下所示

 { name: 'Comments', index: 'Comments', editable: true, editrules: { required: true }, edittype: 'textarea' }
Run Code Online (Sandbox Code Playgroud)

我将如何动态地执行此操作?我想根据另一个字段(如下拉/组合框的选定值)创建一个字段

我知道在哪里放置代码,例如我的下拉选择事件.但不是如何以我提供的代码示例以外的任何其他方式应用所需的属性.

Ole*_*leg 6

我建议您使用某个事件来监视select控件中的更改并更改editrulesrequired选项的.

例如,在演示中,我在'ship_via'列的选择控件上使用'focusout'事件来更改列'note' required编辑规则选项.我使用了'focusout'事件,因为代码使用了我在这里建议的错误修复.您可以选择使用其他事件,但您应该在不同的浏览器中进行测试.

我在演示中使用的代码是

{name: 'ship_via', index: 'ship_via', width: 105, align: 'center', editable: true,
    formatter: 'select', edittype: 'select', editoptions: {
        value: 'FE:FedEx;TN:TNT;IN:Intim',
        defaultValue: 'IN',
        dataEvents: [
            {
                type: 'focusout',
                fn: function (e) {
                    $grid.jqGrid('setColProp', 'note', {
                        editrules: {required: ($(e.target).val() !== "IN")}
                    });
                }
            }
        ]
    },
    stype: 'select', searchoptions: {
        sopt: ['eq', 'ne'],
        value: ':Any;FE:FedEx;TN:TNT;IN:IN'
    } },
{ name: 'note', index: 'note', width: 60, sortable: false, editable: true,
    edittype: 'textarea' }
Run Code Online (Sandbox Code Playgroud)