2011-11-17 119 views
4

我有一種方案,我想對同一個jqgrid應用表單編輯和內聯編輯。我有兩個用戶,例如一個ID管理員和其他用戶和公司是一個jqgrid。現在我想爲管理員應用表單編輯併爲公司Jqgrid的用戶進行內聯編輯。我使用JSP腳本來指定它是Admin還是User。使用內聯編輯進行表單編輯到相同的jqgrid

有誰知道我該如何能夠執行此操作?

@updated:

onSelectRow: function(id){       
       var userType='<%=userDetails[1]%>'; 
       alert("userType= " + userType); 
       if(userType === 'Company Administrator'){     
         jQuery('#companyList').jqGrid('editRow',id,true,inlineEditSuccess);      
       } 
      } 

回答

1

的實施似乎我清楚。您只需在服務器端設置一個JavaScript變量,它將描述用戶可以使用哪種編輯模式。你甚至可以允許一些用戶編輯,而另一個不能。

如果你不想讓任何一種形式的編輯對一些使用可以測試對應的變量的值,並調用navGrid取決於值:

if (my.formEditing) { 
    $("#list").jqGrid('navGrid', '#pager', ....); 
} 

,或者您可以使用

if (my.formEditingOn) { 
    $("#list").jqGrid('navGrid', '#pager', 
     {edit: my.formEditOn, add: my.formAddOn, add: my.formDelOn}, ....); 
} 

如果您要使用the answer中描述的技巧(請參閱the demo),您可以調用'navGrid'並創建所有導航按鈕,但只能根據用戶的權限顯示所選按鈕。

在在線的使用情況下編輯,你可以使用類似

onSelectRow: function (id) { 
    if (!my.inlineEditing) { 
     return; 
    } 
    //... 
    $(this).jqGrid('editRow', id, ...); 
} 

my變量的初始化可以是不同取決於你在服務器端使用的技術。在最簡單的my變量可以定義爲全球在頁面上,因此它可以在頂層定義。在ASP.NET MVC的情況下,代碼可以如下所示:

<%@ Page ... 
... 
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server"> 

<%-- first include script which defines global my object based on the user rights --%> 
<script type="text/javascript"> 
    // initialize my based of Model properties filled 
    var my = { 
     inlineEditing : .., 
     formEditOn : ..., 
     formAddOn : ..., 
     formDelOn : ... 
    } 
</script> 

<%-- now include the main script which uses jqGrid --%> 
<script type="text/javascript" src="<%= Url.Content(scriptPath) %>"></script> 
+0

完成了。正如你指定的那樣,我嘗試了這種方式,因爲我正在檢查onSelectRow事件函數中的用戶類型,因爲用戶類型是從JSP scriptlet即服務器端代碼中取回的。請看看我的@updated代碼,謝謝你的回覆。 –

+0

@Bhagwat:不客氣! – Oleg