3

jqGrid custom formatter option "unformat" doesnt work when supplied with function.

I am supplying function to this option. custom formatter example suppose to work but its not working.

My main purpose of having unformat function is to give proper value to the sort function (when you sort by clicking on the sortable column header) which calls unformat and formatter supplied to the colModel.

Here is my code, (all the modules are included for jquery UI and jqgrid.)

<link href="../css/jquery-ui-1.8.11.custom.css" rel="stylesheet" type="text/css"/>
<link href="../css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../js/jquery-1.5.2.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.11.custom.min.js"></script>
<script type="text/javascript" src="../js/jquery.jqGrid.min.js"></script>


    $("#GridTable").jqGrid({
    datatype: "local",
    colNames: ['id', 'col1', 'col2', 'col3', 'col4'],
    colModel: [{name:'id',index:'id', align:'left', width:'260px'},
                {name:'col1',index:'col1', width:'170px'},
                {name:'col2',index:'col2', width:'160px'},
                {name:'col3',index:'col3', sorttype:'float', width:'110px',unformat: unformatterFunction, formatter: formatterFunction },
                {name:'col4',index:'col4', sorttype:'float', width:'110px'}
             ],
    altRows: true,
    caption: "Test Data",
    height: '100%',
    autowidth : true,
    shrinkToFit: true,
});

function unformatterFunction(cellvalue, options, rowObject){
    if(cellvalue=="-"){
        return "0";
    }
    return cellvalue;
}

function formatterFunction(cellvalue, options, rowObject){
    if(cellvalue > 15){
        return "-";
    }
    return cellvalue;
}

I have spend lot of hours to trace the call into grid.base.js and found no way that goes to jquery.fmatter.js where the unformatFunction gets called for every row. My doubt is unformatFunction is not getting called while sorting.

I just confirmed by editing the example, that it is not working, something is horribly wrong. i can't think of any mistakes. its simply dont call the unformat function specified in colModel.

4

1 回答 1

1

如果您需要自定义对本地 jqGrid 的排序,则使用自定义 unformatter 是错误的方式。您需要的是sorttype用作功能。查看旧答案,包括演示或这个

使用sorttypeas 函数最简单的方法是从函数返回转换后的数据,这些数据应该用于在相应的比较操作中定义,以定义网格中行的顺序。

于 2011-04-01T11:57:39.230 回答