jqgrid排序不正确

jqgrid排序不正确,jqgrid,Jqgrid,我有两个问题。 一,。我在上面的jqgrid表中有排序问题。虽然我对文本的第三列进行了排序,但排序不正确。排序基于第二个字段,这也是不正确的。 二,。如果值为“失败”,如何更改颜色 回答第二个问题。(假设需要更改行的颜色) 如果只需要更改特定单元格的颜色,请替换为: $("#grid").jqGrid({ datastr: mydata, datatype: 'jsonstring', width: 800, colNames:['Slno','Item','Re

我有两个问题。 一,。我在上面的jqgrid表中有排序问题。虽然我对文本的第三列进行了排序,但排序不正确。排序基于第二个字段,这也是不正确的。 二,。如果值为“失败”,如何更改颜色


回答第二个问题。(假设需要更改行的颜色)

如果只需要更改特定单元格的颜色,请替换为:

$("#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
    });

然后换颜色

您也可以使用如下所示的格式化程序

 {name:'result', index:'result', width:30, sorttype: 'text'},
{name:'result',index:'result',width:30,sorttype:'text',格式化程序:passedOrFailedFormatter},
函数passedOrFailedFormatter(单元格值、选项、行对象){
如果(cellvalue==“已通过”){
返回“+cellvalue+”;
}否则{
返回“+cellvalue+”;
}
}

您应该发布您使用的JavaScript代码。添加了java脚本@oleg要修复排序,您需要从
'result'
的定义中删除
索引:'item'
,或将其更改为
索引:'result'
。我建议您删除所有
index
属性。要设置“失败”单元格的颜色,可以使用
cellatr
(请参阅)或使用
rowattr
设置整行的颜色(请参阅)。答案的想法是正确的。使用错误的
索引是主要问题。另一方面,我不建议使用HTML4.01中不推荐的、HTML5中不包含的。可以使用CSS样式
颜色
直接分配给单元格(
)<代码>样式
是单元格的属性,可用于每个格式化程序。因此,最好使用
rowattr
(请参阅)而不是自定义格式化程序。例如,您可以使用
格式化程序:“data”
并更改颜色。@Oleg感谢您对标记的建议以及RowAttr的使用。谢谢。我试试你的解决办法。
afterInsertRow: function ( rowid, rowdata )
                        {
                            if ( ( rowdata.result) == 'Failed' )
                            {
                               $(this).jqGrid('setCell', rowid, "result", "", { 'background-color': '#EBADAD'
                            });
                            },
        rowNum: 30
    });
 {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>";
        }

    }