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>