jqgrid custom unformat not called when getrowdata()

I used custom formatter and unformat for the column in jqGrid:

{name: 'STATUS', index: 'STATUS',width:145,align:'center',fixed:true, formatter:statusFormatter, unformat:statusUnFormatter}


function statusFormatter(cellvalue, options, rowObject){
    var icon = '';
    var label = '<span class="label status-label">';
    switch (cellvalue){
        case 'Rejected': {
            icon = '<i class="fa fa-times"></i>'; 
            label = '<span class="label label-primary status-label">';break;}
        case 'Approved': {
            icon = '<i class="fa fa-check"></i>'; 
            label = '<span class="label label-primary status-label">';break;}   
        default: break;
    return label + icon+"&nbsp" +cellvalue + '</span>';


function statusUnFormatter(cellvalue, options, cell){
    var html = '<div>' + cellvalue + '</div>';
    return html.text();

Table looks like this: Column after formatted

Problem happens when I use getrowdata(), it returns the content instead of the original value of the cell. Result of alert()

onCellSelect: function(id, icol, cellcontent, e){
    var status = $(this).getRowData(id).STATUS;

Answers 1

  • I found the problem in my unformat function.
    I did not wrap the string in a jQuery object, so the text() method doesnt work.

    This code works:

    function statusUnFormatter(cellvalue, options, cell){
        var text = $('<div>' + cellvalue + '</div>').text();
        return text.trim();

Related Articles