我使用自定义格式化程序并取消格式化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+" " +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);
}
答案 0 :(得分:1)
我在unformat函数中发现了这个问题。
我没有将字符串包装在jQuery对象中,因此text()方法不起作用。
此代码有效:
function statusUnFormatter(cellvalue, options, cell){
var text = $('<div>' + cellvalue + '</div>').text();
return text.trim();
}