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}

Formatter:

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>';
}

Unformat:

function statusUnFormatter(cellvalue, options, cell){
    var html = '<div>' + cellvalue + '</div>';
    html.find('i').removeClass();
    html.find('span').removeClass();
    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;
    alert(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