JQgrid : Change entire row's font color if one column is filled

标签 jqgrid fonts compiler-errors jqgrid-formatter

我已经阅读了一些帖子,但由于我是 jqgrid 的新手,所以我仍然无法关注。 我有一个 jqgrid,它有 5 列,但一开始有 1 列是空的。 进行一些更新后,它将被填充。

我希望 JQgrid 更改该行的字体颜色,因此如果填充了该行,则将字体颜色更改为蓝色。

jQuery("#list").jqGrid({
....
colModel :[ 
        {name:'prob_id', index:'prob_id', hidden:true, width:10}, 
        {name:'Model',index:'Model',width:100,editable:true,search:true,stype:'text',searchoption:{sopt:['cn']}}, 
        {name:'Serial', index:'Serial',width:80,editable:true,search:true,stype:'text',searchoptions:{sopt:['cn']}},
        {name:'Lotno', index:'Lotno', width:50, editable:true,
                 search:true,
                 stype:'text',
                 searchoption:{sopt:['cn']}},
        {name:'Detail', index:'Detail', hidden:true,width:70,formatter:myformat}
                                        ],
....

function myformat ( cellvalue, options, rowObject )
                {
                        if (!empty(cellvalue)){
                        return '<font color="blue">' + cellvalue + '</font>';//or use classes
                        } else{
                        return '<font color="black">' + cellvalue + '</font>';//or use classes
                        }
                }

我想更改具有详细信息字段值的所有行的字体颜色

但我收到错误:

empty is not defined 

更新

试试这个方法: 我决定将条件移至:

function myformat ( cellvalue, options, rowObject )
                {
                        if (cellvalue == "closed"){
                        return '<font color="blue">' + cellvalue + '</font>';//or use classes
                        } else{
                        return '<font color="black">' + cellvalue + '</font>';//or use classes
                        }
                }

它可以工作,但似乎只有一列变成蓝色,我想要整行都具有条件​​CLOSED

最佳答案

尝试 afterInsertRow 和 setRowData,如下面给出的代码

   afterInsertRow: function(rowid, rowData, rowelem) {
   var detail= rowData['Detail'];
   if(detail=="Closed"){
$(this).jqGrid('setRowData', rowid, false, { color: '#000' });
  }else {
$(this).jqGrid('setRowData', rowid, false, { color: '#FF0000' });
    }
    },

删除gridView:true(如果gridView为true,afterInsertRow将不起作用)

关于JQgrid : Change entire row's font color if one column is filled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14908962/

相关文章:

C# 字体字符渲染(GDI Bug)?

不满足 Rust 特征边界。中间分配是必要的,或者删除 Trait 实现

excel - EXCEL VBA : Listview object feature not found when exporting XLAM file to another machine

jquery - document.ready 中声明的函数未定义?

iphone - lineHeight 和领先之间有什么区别?

javascript - jqGrid - 执行操作之前的模式窗口

css - 我如何让字体像这样平滑显示?

compiler-errors - 无法编译 x86_64 .s 和 .c 文件 : undefined reference to function

javascript - jqGrid 通过 javascript 对象添加本地数据

jquery - MongoDB 相当于 SQL "TOP"