4

I have one scenario in which I want to apply both form editing and inline editing for same jqgrid. I have two users for example one id Admin and other is user and company is a jqgrid. now I want to apply form editing for Admin and inline editing for User for company Jqgrid. I am using JSP scriptlets for specify whether it is Admin or User.

Is anyone knows how can I able to implement this please?

@updated :

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

1 Answers1

1

The implementation seems me clear. You need just set on the server side a JavaScript variable which will describe which editing mode the user can use. You can even allow some user editing and another not.

If you not want to allow any kind of form editing for some use you can test the value of the corresponding variable and call navGrid depend on the value:

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

or you can use

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

If you would use the trick described in the answer (see the demo) you can call 'navGrid' and create all navigator buttons, but make only selected buttons visible depend on the user's permissions.

In case of usage of inline editing you can use something like

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

The initializing of the my variable can be different depend on the technology which you use on the server side. In the simplest the my variable can be define as global on the page so it can be defined on the top level. In case of ASP.NET MVC the code can look like the following:

<%@ 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>
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • It's done. As you specify I tried in that way as I am checking user type in onSelectRow event function as user type is retrive from JSP scriptlet i.e server side code. Please look out my @updated code ,Thanks for reply. – Bhagwat Gurle Nov 17 '11 at 09:18