2015-06-03 32 views
1

我有一個預定義字段中的值的網格,我想要做的是單擊編輯一行想要更改FormEdit中的一個字段的值。jqGrid更改beforeShowForm上的字段的值

的ColModel是:

colModel:[ 
       {name:'id',index:'ID', width:50, hidden:true, search:false, editable:false,resizable:false}, 
       {name:'product',index:'product', align:"center", width:20, search:false, editable:false,resizable:false}, 
       {name:'volume',index:'volume', align:"center", hidden:false, width:15, search:false, editable:true} 
       ], 

我將建立體積= 1時,打開編輯表單,和我做這樣的...

ondblClickRow: function(id){ 
       jQuery("#products").jqGrid('editGridRow', id, { 
        recreateForm:true, 
        beforeShowForm: function(form) { 
         $('#tr_volume',form).show(); 
         $("#tr_volume",form).val('1'); 
         }, 
        reloadAfterSubmit:false, closeOnEscape:true, closeAfterAdd:true, closeAfterEdit:true, 
        editable:true, editrules:{edithidden:true,required:true,number:true,minValue:1}      
       }) 

但它不是爲我工作,是什麼是錯的?

回答

1

您不使用hidden: truevolume欄的屬性。所以設置$('#tr_volume',form).show()是不需要的。 $("#tr_volume",form).val('1')的設置錯誤,因爲<tr>元素沒有任何價值。我認爲你需要使用$("#volume",form).val('1')$("#volume").val('1')<input>字段與id="volume"(與列名稱相同的id)將在表單中創建。這是你可能試圖改變的領域。

+0

謝謝奧列格!它很棒! – Sici

+0

@Sici:不客氣!如果問題解決了,您應該[「接受」](http://meta.stackexchange.com/a/5235/147495)答案並獲得您的第一個聲望點。 – Oleg