我有一个jqGrid,其中colModel的格式化程序函数必须定义为字符串。
{name:'FileSize', index:'FileSize', width:90, editable: true,
formatter: 'fileSizeFormatter'}在格式化程序函数不是字符串的情况下,我不能使用以下方法,因为我在C#服务器端构建了colmodel。如果我可以使用非字符串格式化程序,定义未格式化程序将是一个解决方案,如这里所示
{name:'FileSize', index:'FileSize', width:90, editable: true,
formatter: fileSizeFormatter}下面是我使用fileSizeFormatter所需的fn.fmatter,因为格式化程序是作为字符串传递的,并且代码假定它是预定义的文件"select",“...etc”
$.fn.fmatter.fileSizeFormatter = function (cellval, options) {
var fileUnit = "B";
if (cellval) {
var fileUnit;
var iKBFileSize;
if (cellval < 1024) {
iKBFileSize = cellval;
} else {
iKBFileSize = cellval / 1024;
fileUnit = "KB";
}
var result = iKBFileSize.toFixed(1) + fileUnit;
return result;
}
return cellval + fileUnit;
};因此,问题是如何为作为字符串传递的格式化程序定义未格式化程序。当我执行grid.getrowdata或编辑单元格时,不使用我的未格式化程序。它正在用文件单元给我数据。
$.unformat.fileSizeFormatter = function (cellvalue, options, cell) {
return $('input', cellval).is(":checked") ? true : false;
};发布于 2016-05-18 22:38:45
您应该用另一种方式来定义未格式化程序:
$.fn.fmatter.fileSizeFormatter.unformat = function (cellValue, options, elem) {
return $(elem).find('input').is(":checked") ? true : false;
}您应该在定义格式化程序($.fn.fmatter.fileSizeFormatter)之后定义原因的未格式化程序。
https://stackoverflow.com/questions/37311081
复制相似问题