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 テーブルにソートの問題があります。テキストである 3 列目を並べ替えていますが、正しく並べ替えられていません。ソートは2番目のフィールドに基づいていますが、これも適切ではありません。

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

結果のインデックスが間違っています

変化する

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

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

次に、色を変更するには、この回答を参照してください

または 、以下のようなフォーマッターを使用することもできます

 {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

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:'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 に答える