我已经阅读了一些帖子,但由于我是 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/