在Jqgrid中,您将必需的属性应用于任何给定的字段,例如
{ name: 'Comments', index: 'Comments', editable: true, editrules: { required: true }, edittype: 'textarea' }
我将如何动态地执行此操作? 我想根据另一个字段(如下拉/组合框的选定值)创建一个字段
我知道在哪里放置代码,例如我的下拉列表选择事件。但不是如何以我提供的代码示例以外的任何其他方式应用所需的属性..
答案 0 :(得分:6)
我建议您使用某个事件来监控选择控件中的更改,并更改editrules的required
选项的值。
例如在the demo中,我在'ship_via'列的选择控件上使用'focusout'事件来更改列'note'的editrules required
选项。我使用了'focusout'事件,因为代码使用了我建议here的错误修复。您可以选择使用其他事件,但您应该在不同的浏览器中进行测试。
我在演示中使用的代码是
{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' }