getrowdata() 时未调用 jqgrid 自定义取消格式化
jqgrid custom unformat not called when getrowdata()
我对 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>';
}
取消格式化:
function statusUnFormatter(cellvalue, options, cell){
var html = '<div>' + cellvalue + '</div>';
html.find('i').removeClass();
html.find('span').removeClass();
return html.text();
}
Table 看起来像这样:
Column after formatted
当我使用 getrowdata() 时出现问题,它 returns 内容而不是单元格的原始值。 Result of alert()
onCellSelect: function(id, icol, cellcontent, e){
var status = $(this).getRowData(id).STATUS;
alert(status);
}
我在我的格式化函数中发现了问题。
我没有将字符串包装在 jQuery 对象中,因此 text() 方法不起作用。
此代码有效:
function statusUnFormatter(cellvalue, options, cell){
var text = $('<div>' + cellvalue + '</div>').text();
return text.trim();
}
我对 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>';
}
取消格式化:
function statusUnFormatter(cellvalue, options, cell){
var html = '<div>' + cellvalue + '</div>';
html.find('i').removeClass();
html.find('span').removeClass();
return html.text();
}
Table 看起来像这样: Column after formatted
当我使用 getrowdata() 时出现问题,它 returns 内容而不是单元格的原始值。 Result of alert()
onCellSelect: function(id, icol, cellcontent, e){
var status = $(this).getRowData(id).STATUS;
alert(status);
}
我在我的格式化函数中发现了问题。
我没有将字符串包装在 jQuery 对象中,因此 text() 方法不起作用。
此代码有效:
function statusUnFormatter(cellvalue, options, cell){
var text = $('<div>' + cellvalue + '</div>').text();
return text.trim();
}