13 1.1.16 Failed
14 1.1.17 Failed
15 1.1.18 Failed
16 1.1.19 Passed
2 1.1.2 Failed
17 1.1.20 Failed
18 1.1.21 Passed
19 1.1.22 Passed
我有2个查询。
1.我在上面的jqgrid表中有排序问题。虽然我将第3列排序为文本,但它没有正确排序。排序是基于第二个字段,这也是不合适的。
2。如果值为“失败”,如何更改颜色。
$("#grid").jqGrid({
datastr: mydata,
datatype: 'jsonstring',
width: 800,
colNames:['Slno','Item','Result', 'Desc'],
colModel:[
{name:'slno', index:'slno', key: true, width:50, sorttype: 'int'},
{name:'item', index:'item', width:50, sortable: false},
{name:'result', index:'item', width:30, sorttype: 'text'},
{name:'desc', index:'desc', width:100}
],
pager: '#pager',
viewrecords: true,
sortorder: "asc",
caption:"jqGrid Example",
jsonReader: {
root: "rows",
repeatitems: false,
id: "0"
},
rowNum: 30
});
答案 0 :(得分:2)
您的结果索引错误
更改
{name:'result', index:'item', width:30, sorttype: 'text'},
到
{name:'result', index:'result', width:30, sorttype: 'text'},
然后改变颜色See this answer
或强> 你也可以使用下面给出的格式化程序
{name:'result', index:'result', width:30, sorttype: 'text',formatter:passedOrFailedFormatter},
function passedOrFailedFormatter(cellvalue, options, rowObject) {
if (cellvalue=="Passed") {
return "<font color=#008000> "+ cellvalue +" </font>";
} else {
return "<font color=#FF0000> "+ cellvalue +" </font>";
}
}
答案 1 :(得分:0)
回答第二个问题。(假设您需要更改行的颜色)
$("#grid").jqGrid({
datastr: mydata,
datatype: 'jsonstring',
width: 800,
colNames:['Slno','Item','Result', 'Desc'],
colModel:[
{name:'slno', index:'slno', key: true, width:50, sorttype: 'int'},
{name:'item', index:'item', width:50, sortable: false},
{name:'result', index:'result', width:30, sorttype: 'text'},
{name:'desc', index:'desc', width:100}
],
pager: '#pager',
viewrecords: true,
sortorder: "asc",
caption:"jqGrid Example",
jsonReader: {
root: "rows",
repeatitems: false,
id: "0"
},
afterInsertRow: function ( rowid, rowdata )
{
if ( ( rowdata.result) == 'Failed' )
{
$( this ).jqGrid( 'setRowData', rowid, false, { background: '#EBADAD'} );//
},
rowNum: 30
});
如果您只需更改该特定单元格的颜色,请替换为:
afterInsertRow: function ( rowid, rowdata )
{
if ( ( rowdata.result) == 'Failed' )
{
$(this).jqGrid('setCell', rowid, "result", "", { 'background-color': '#EBADAD'
});
},
rowNum: 30
});