getrowdata()时未调用jqgrid自定义unformat

时间:2016-03-28 02:48:51

标签: jquery jqgrid formatter

我使用自定义格式化程序并取消格式化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>';
}

UNFORMAT:

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

表格如下: Column after formatted

当我使用getrowdata()时会出现问题,它会返回内容而不是单元格的原始值。 Result of alert()

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

1 个答案:

答案 0 :(得分:1)

我在unformat函数中发现了这个问题。
我没有将字符串包装在jQuery对象中,因此text()方法不起作用。

此代码有效:

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