问题描述
我希望能够在用户尝试编辑行时将字段传递到编辑表单中,但是我不希望这些字段可编辑-我希望将它们隐藏起来,以便仍将它们发送到服务器.
I want to be able to pass fields into the edit form when a user attempts to edit a row, but I don't want these fields to be editable - I want them to just be hidden so they still get sent to the server.
例如:
colModel :[
{label: 'Game ID', name: 'game_id', editable:true},
{label: 'Component ID', name: 'component_id', editable:true},
{label: 'Table ID', name: 'table_id', editable:true},
],
这会将它们传递到编辑表单(由于editable:true
),但是不幸的是,它们将可由用户编辑.我想隐藏这些字段,以便用户无法对其进行编辑.
This will pass them to the edit form (because of editable:true
) but unfortunately they will be editable by the user. I want to hide these fields so the user can't edit them.
我该怎么做?
推荐答案
编辑
好吧,事实证明您可以将自定义元素定义为 edittype .对于您的情况,您可以执行以下操作:
Okay, turns out you can define a custom element as an edittype. For your situation, you'd do the following:
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
:
Then you'd define myelem
and myval
like so:
function myelem(value,options){
return $('<input type="text" value="'+value+'" disabled="disabled"/>');
}
function myval(elem){
return elem.val();
}
这将构造一个禁用的文本字段,并且看上去比afterShowForm
少点黑客气.
This will construct a disabled text field, and seems less hack-ish than afterShowForm
.
原始
如果您使用的是编辑表单控件(而不是内联编辑),则您似乎必须提供 afterShowForm 函数(向下滚动至事件"部分).参见此问题.
If you're using an edit form control (not inline editing), it looks like you have to provide an afterShowForm function (scroll down to the Events section). See this question.
您似乎希望这些列显示在视图中,但不可编辑.如果设置editable:true
,则用户无论如何都可以编辑该字段.您最终要做的是禁用/将form元素设置为hidden,以便用户无法更改其值. afterShowForm
然后看起来像:
It looks like you want the columns to show up in the view, but not be editable. If you set editable:true
, then the user can edit the field no matter what. What you'll end up having to do is disable / set the form element to hidden so the user can't change it's value. afterShowForm
would then look something like:
afterShowForm: function(eparams){
// change the selector appropriately
$('#jqGrid input[name=game_id]').attr('type','hidden');
// or $('#jqGrid input[name=game_id]').attr('disabled','disabled');
}
这篇关于jqGrid-如何在编辑表单中隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!