JQGrid Colmoldel格式化变量



(版本免费JQGrid 4.13.6(

我有一些我定义为{...格式化:" date" ...}的DateTime列,没关系。

现在,在某些情况下,根据现场价值,我需要使用另一个自定义格式。由于格式化:"日期"是jqgrid本地人,我不知道如何解决这种情况。

示例:通常,字段值是DateTime,例如" 2017-04-18 10:06",对于格式化者来说是可以的:" date"。但是,在某些情况下,该值是字符串,例如"所有日期"。仅在这些情况下,格式化器必须是" mycustomformatter",不格式化:"日期",因为我不想修改JQGrid本地"日期"功能以考虑此特殊情况。

我建议您检查免费JQGrid代码的行,以查看自定义格式化器的调用与预定义的格式化器之间的区别(例如 formatter: "date"(:

...
} else if (isFunction(cm.formatter)) {
    v = cm.formatter.call(ts, cellval, opts, rwdat, act);
} else if ($.fmatter) {
    v = $.fn.fmatter.call(ts, cm.formatter, cellval, opts, rwdat, act);
} else {
...

这意味着要从自定义格式化拨打formatter: "date",只需使用

 formatter: function (cellValue, options, rowObject, action) {
     return $.fn.fmatter.call(this, "date", cellValue, options, rowObject, action);
 },
 unformat: function (cellValue, options, cell) {
     return $.unformat.date.call(this, cellValue, options.formatoptions);
 }

上面的代码刚刚将电话转到格式日期。请参阅https://jsfiddle.net/olegki/gq5hxtnc/

您最终需要做的是修改自定义格式器上的上述代码以将调用转发到formatter: "date",但例如,如果输入不是字符串"ALL DATES"

您可以使用Custom 格式对列如下。

formatter: function(cellvalue, options, rowObject) {
    var date = new Date(cellvalue);
    if(isNaN(date.getFullYear())){
        return cellvalue;
    } else {
        return date.getDate()  + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
    }
}

demo

最新更新