Jay99
Jay99

Reputation: 111

jqGrid custom formatter option "unformat" doesnt work

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.

Upvotes: 3

Views: 6383

Answers (1)

Oleg
Oleg

Reputation: 221997

If you need customize to sorting of the local jqGrid the usage of custom unformatter is the wrong way. What you need is to use sorttype as the function. Look at the old answer including the demo or this one.

The simplest way to use the sorttype as the function is to return from the function converted data which should be used to define in the corresponding compare operation to define the order of the row in the grid.

Upvotes: 1

Related Questions