用于预定义格式化程序的 jqGrid Unformatter

jqGrid Unformatter for predefined formatter

我有一个 jqGrid,其中 colModel 的格式化程序函数必须定义为字符串

{name:'FileSize', index:'FileSize', width:90, editable: true, 
                                            formatter: 'fileSizeFormatter'}

我不能在格式化程序函数不是字符串的地方使用以下内容,因为我在服务器端使用 C# 构建了 colmodels。如果我可以使用非字符串格式化程序定义取消格式化程序将是一种解决方案,如 所示 这里

{name:'FileSize', index:'FileSize', width:90, editable: true, 
                                                formatter: fileSizeFormatter}

这里是我需要使用的 fileSizeFormatter fn.fmatter 因为我的格式化程序作为字符串传递并且代码假定它是预定义的文件之一 "select", "currency" ...等等

$.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;
};

Sample

所以问题是我如何为作为字符串传递的格式化程序定义取消格式化程序。当我执行 grid.getrowdata 或编辑单元格时,未使用我的格式化程序。它以文件为单位获取数据。

$.unformat.fileSizeFormatter = function (cellvalue, options, cell) {
    return $('input', cellval).is(":checked") ? true : false;
};

您应该以另一种方式定义取消格式化程序:

$.fn.fmatter.fileSizeFormatter.unformat = function (cellValue, options, elem) {
    return $(elem).find('input').is(":checked") ? true : false;
}

您应该在定义格式化程序($.fn.fmatter.fileSizeFormatter)之后再定义unformatter of cause。