编辑
好的,事实证明您可以将自定义元素定义为edittype。根据您的情况,您可以执行以下操作:
colModel :[
{label: 'Game ID', name: 'game_id', editable:true, edittype:'custom',editoptions:{custom_element:myelem,custom_value:myval}},
{label: 'Component ID', name: 'component_id', editable:true, edittype:'custom',editoptions:{custom_element:myelem,custom_value:myval} },
{label: 'Table ID', name: 'table_id', editable:true, edittype:'custom',editoptions:{custom_element:myelem,custom_value:myval}}
]
然后你会像这样定义myelem 和myval:
function myelem(value,options){
return $('<input type="text" value="'+value+'" disabled="disabled"/>');
}
function myval(elem){
return elem.val();
}
这将构建一个禁用的文本字段,并且看起来不像 afterShowForm 那样骇人听闻。
原创
如果您使用的是编辑表单控件(不是内联编辑),看起来您必须提供一个afterShowForm 函数(向下滚动到“事件”部分)。见this question。
您似乎希望列显示在视图中,但不可编辑。如果您设置editable:true,那么用户无论如何都可以编辑该字段。您最终要做的是禁用/将表单元素设置为隐藏,这样用户就无法更改它的值。 afterShowForm 然后看起来像:
afterShowForm: function(eparams){
// change the selector appropriately
$('#jqGrid input[name=game_id]').attr('type','hidden');
// or $('#jqGrid input[name=game_id]').attr('disabled','disabled');
}