jqGrid隐藏视图上的列取决于另一个列的值 [英] jqGrid hide column on view depends another column value

查看:143
本文介绍了jqGrid隐藏视图上的列取决于另一个列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据相应行的单元格值type显示列session. session列已被隐藏.

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

为了隐藏session列,我在下面的代码段中使用了此代码,

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

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

因此,我只想仅在view中显示此列值.如果type单元格值等于Full,我想在view中隐藏session.否则,我想显示view中的session列值.

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;
}

一次,第一个if条件获得成功,edithidden属性更改为false.因此,它将session隐藏在视图"窗体中.但是当我的第二个if条件获得成功时,我无法将该属性更改为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?

推荐答案

我建议您使用View选项的beforeShowFormafterclickPgButtons回调. 演示进行了演示.演示以下代码:

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
});

该演示仅在查看"表单上显示"id"列,并且仅在选中关闭"列中的复选框时显示.

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

这篇关于jqGrid隐藏视图上的列取决于另一个列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆