Lib.Web.Mvc.JQuery.JqGrid - Enable editing of column ONLY while being added, but not while being "edited"

230 Views Asked by At

I have a column that happens to be both a business key and a primary key for a particular entity in an existing, poorly-designed schema. It is impractical to allow edits to this key as they will not cascade as-is.

So I need to make a column editable only when creating but not when editing. I could not find anything in the documentation for jqGrid or Lib.Web.Mvc.JQuery.JqGrid that suggests this is a built-in feature, but if it is, I would love to know about it.

If not, what would be the best way for me to proceed in achieving this functionality? Should I make the column editable but add a custom (client-side) formatter? Is there another way?

Note: This is not a duplicate of jqGrid need a field editable on Add dialog but not Edit dialog because it pertains specifically to Lib.Web.Mvc.JQuery.JqGrid and not the JavaScript library in general.

All help appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

Here is how I am doing it for now. This feels "wrong" and ugly to me, but it does work.

    function fnSetAccessGroupCodeReadOnly() {
        $("#AccessGroupCode").attr("readonly", "readonly");
    }

    function fnUnSetAccessGroupCodeReadOnly() {
        $("#AccessGroupCode").removeAttr("readonly");
    }

and in the helper, in the action navigator for edit:

    new JqGridNavigatorEditActionOptions()
    {
        // Edit Options

        Url = Url.Action("EditPartnerAccessGroup"),
        MethodType = JqGridMethodTypes.Post,
        AfterShowForm = "fnSetAccessGroupCodeReadOnly",
        CloseAfterEdit = true
    },