jqGrid hide column on view depends another column value
Asked Answered
D

1

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?

Dissimilation answered 2/4, 2014 at 13:43 Comment(0)
S
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.

Sills answered 2/4, 2014 at 14:55 Comment(2)
Thanks... Its working fine... We should recreateForm for each view?Dissimilation
@CJRamki: You are welcome! I strictly recommend to use recreateForm: true for Add, Edit and View and recreateFilter: true for searching.Sills

© 2022 - 2024 — McMap. All rights reserved.