在 Jqgrid 中,您将必需的属性应用于任何给定的字段,如下所示
{ name: 'Comments', index: 'Comments', editable: true, editrules: { required: true }, edittype: 'textarea' }
我将如何动态地执行此操作?我想根据另一个字段(如下拉/组合框的选定值)创建一个必填字段
我知道在哪里放置代码,例如,我的下拉列表的选择事件。但不是如何以除我提供的代码示例之外的任何其他方式应用所需属性。
在 Jqgrid 中,您将必需的属性应用于任何给定的字段,如下所示
{ name: 'Comments', index: 'Comments', editable: true, editrules: { required: true }, edittype: 'textarea' }
我将如何动态地执行此操作?我想根据另一个字段(如下拉/组合框的选定值)创建一个必填字段
我知道在哪里放置代码,例如,我的下拉列表的选择事件。但不是如何以除我提供的代码示例之外的任何其他方式应用所需属性。
我建议你使用一些事件来监控 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' }