0
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 表中有排序问题。当我对作为文本的第三列进行排序时,它没有正确排序。排序基于第二个字段,这也是不正确的。

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

2 回答 2

2

You have wrong index for result

change

 {name:'result', index:'item', width:30, sorttype: 'text'},

to

 {name:'result', index:'result', width:30, sorttype: 'text'},

Then to change color See this answer

Or you can also use formatter like given below

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

    }
于 2013-03-22T04:58:44.853 回答
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
    });
于 2013-03-22T04:50:41.827 回答