1

I want to show column session based on the corresponding row's cell value of type. Already session column is hidden.

To hide session column i used this below piece of code,

{ name: 'session', index: 'session', hidden:true, editrules:{edithidden:true} },

So, I just want to show this column value only in view. If type cell value is equal to Full, I want to hide session in view. Otherwise, I want to show that session column value in view.

I tried using this below code,

onSelectRow: function (id) {
    var celValue = $('#statGrid').jqGrid('getCell', id, 'type');
    if (celValue === 'Full') $('#statGrid').jqGrid('getColProp', 'session').editrules.edithidden = false;
    if (celValue === 'Half') $('#statGrid').jqGrid('getColProp', 'session').editrules.edithidden = true;
}

Once, first if condition get success edithidden property changed to false. So, It hides session in View form. But I could not change that property to true when my second if condition get success.

Why this happened? Is this right way to do this task? or Is there any better way to do this?

1 Answer 1

1

I would recommend you to use beforeShowForm and afterclickPgButtons callbacks of View options. The demo demonstrate it. The demo the the following code:

var showIdRow = function ($form) {
        var $this = $(this),
            rowid = $this.jqGrid("getGridParam", "selrow"),
            isClosed = $this.jqGrid("getCell", rowid, "closed");
        if (isClosed === "Yes") {
            $("#trv_id").show(); // "trv_" is the prefix, "id" is the column name
        }
    };

$("#list").jqGrid({
    ....
    colModel: [
        { name: "id", width: 65, hidden: true,  editrules: {edithidden: false} },
        ...
    ]
    ...
}).jqGrid("navGrid", "#pager", {view: true}, {}, {}, {}, {}, {
    recreateForm: true,
    afterclickPgButtons: showIdRow,
    beforeShowForm: showIdRow
});

The demo shows "id" column on View form only and only in case if chechbox in "Close" column is checked.

2
  • Thanks... Its working fine... We should recreateForm for each view?
    – CJ Ramki
    Apr 3, 2014 at 7:12
  • @CJRamki: You are welcome! I strictly recommend to use recreateForm: true for Add, Edit and View and recreateFilter: true for searching.
    – Oleg
    Apr 3, 2014 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.