【问题标题】:jqgrid custom unformat not called when getrowdata()getrowdata()时未调用jqgrid自定义unformat
【发布时间】:2016-07-15 06:57:52
【问题描述】:

我对 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>';
    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);
}

【问题讨论】:

    标签: jquery jqgrid formatter


    【解决方案1】:

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

    此代码有效:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多