2010-01-01 126 views
4

我有一個jqGrid,其中包含要在表單中編輯的用戶信息。用戶名是不可變的,但應該出現在表單中,以便用戶知道他們正在編輯哪個用戶。密碼只能編輯。所以在我的colModel我有這樣的設置:如何在jqGrid中添加和編輯表單的不同編輯選項

{name:'username', index:'username', width:155, editable:true, editoptions: {readonly:'readonly'}}, 
{name:'password', index:'password', width:155, hidden:true, editable: true, edittype:'password', editrules:{edithidden:true}}, 

這適用於編輯。我的問題是添加我需要使用戶名'不只讀'。我沒有看到屬性來控制添加窗體與編輯窗體。也許我可以使用afterShowForm事件來更改editoptions?有人做過這樣的事嗎?

回答

6

如果對其他人有用,我不能完全做到這一點,但找到了一種方法來完成最終結果。

因此,不使用editoptions將表單字段設置爲只讀,而是使用添加&編輯選項的beforeShowForm事件來添加和刪除readonly屬性。

因此,沒有隻讀的colmodel:

{name:'username', index:'username', width:155, editable:true}, 
{name:'password', index:'password', width:155, hidden:true, editable: true, edittype:'password', editrules:{edithidden:true}}, 

和navGrid編輯&添加選項打開只讀決定(添加)或關閉(用於編輯)。注意,INPUT標記的ID將是name字段的colModel值:

jQuery("#user-grid").jqGrid('navGrid','#user-grid-pager', 
    { }, //options 
    { // edit options 
     beforeShowForm: function(frm) { 
      $('#username').attr('readonly','readonly'); 
     } 
    }, 
    { // add options 
     beforeShowForm: function(frm) { 
      $('#username').removeAttr('readonly'); 
     } 
    }, 
    { }, // del options 
    { } // search options 
); 

在一個側面說明,(根據jQuery的轉儲)「FRM」功能arg是包含一個jQuery對象,而我知道表單,我無法讓選擇器成功選擇我想要的孩子,所以我只使用了與colModel名稱相匹配的id。

+0

只想說感謝 - 我有完全相同的要求ents,我無法弄清楚如何調用beforeShowForm函數。這正是我所需要的 - 再次感謝。 – 2010-03-06 22:44:27

+0

同上。感謝您的發表。這節省了我相當多的時間。 – 2010-05-16 19:58:18

相關問題