jqGrid hide column on view depends another column value

笑着哭i 提交于 2019-12-11 04:56:56

问题


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:


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.



来源:https://stackoverflow.com/questions/22813413/jqgrid-hide-column-on-view-depends-another-column-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!