jqGrid:选择框值格式化程序问题 [英] jqGrid : Select box value formatter issue

查看:56
本文介绍了jqGrid:选择框值格式化程序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个jqGrid中有一个status列.它保持值为0或1.对我来说,0表示未激活,而1表示已激活.因此,我使用格式化程序在网格中显示有效/无效而不是0/1. 当我要编辑记录时,我发现没有在选择框中预先选择正确的值.在编辑视图中,选择框始终将活动"显示为选定项.但是,如果我在网格中显示0/1而不是使用格式化程序,则编辑窗口会在selectbox所选项目中显示正确的值.但是我需要显示活动/不活动而不是0/1.

I have a status column in one of my jqGrid. It holds value 0 or 1. To me 0 means inactive and 1 means active. So i use a formatter to show the Active/Inactive instead of 0/1 in the grid . When I'm going to edit the record I'm getting that the correct value is not pre selected in the selectbox. In edit view the selectbox always shows Active as selected item. But If I show 0/1 in the grid instead of using the formatter then the edit windows shows the correct value in the selectbox selected item. But I need to show Active/Inactive instead of 0/1.

格式化程序

formatter: function(cellValue, options,
                        rowObject) {
                        var val="";
                        if(cellValue=='1')
                            val= "Active";
                        else if(cellValue=='0')
                            val='<span class="cellWithoutBackground" style="background-color:#FFF4F4;color:red;">Inactive</span>';
                        else
                            val= '';

                        return val;

推荐答案

我建议您使用formatter: "select"(请参阅文档答案这一个有关cellattr用法的更多示例.

I would recommend you to use formatter: "select" (see the documentation here) with optional cellattr to set the color of the cell additionally which changes color/background of the cell with "Inactive". See the answer and this one for more examples about the usage of cellattr.

如果您需要突出显示整行而不是一个单元格,则可以使用rowattr而不是cellattr(请参见此处).

If you would need to highlight the whole row instead of one cell you can use rowattr instead of cellattr (see here).

这篇关于jqGrid:选择框值格式化程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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