【发布时间】:2010-05-21 13:53:57
【问题描述】:
对于我的 jqGrid 中的一列,我提供了一个自定义格式化程序函数。我提供了一些特殊情况,但如果不满足这些条件,我想求助于使用内置的日期格式化程序实用方法。我似乎没有得到正确的 $.extend() 组合来创建该方法所期望的选项。
本专栏的我的 colModel:
{ name:'expires',
index:'7',
width:90,
align:"right",
resizable: false,
formatter: expireFormat,
formatoptions: {srcformat:"l, F d, Y g:i:s A",newformat:"n/j/Y"}
},
还有一个我正在尝试做的例子
function expireFormat(cellValue, opts, rowObject) {
if (cellValue == null || cellValue == 1451520000) {
// a specific date that should show as blank
return '';
} else {
// here is where I'd like to just call the $.fmatter.util.DateFormat
var dt = new Date(cellValue * 1000);
var op = $.extend({},opts.date);
if(!isUndefined(opts.colModel.formatoptions)) {
op = $.extend({},op,opts.colModel.formatoptions);
}
return $.fmatter.util.DateFormat(op.srcformat,dt,op.newformat,op);
}
}
(在 DateFormat 方法的内部引发了一个异常,看起来它试图读取传入的选项的掩码属性)
编辑:
将所有内容放在所需位置的 $.extend 是从 i18n 库设置它的全局属性 $.jgrid.formatter.date 中获取的。
var op = $.extend({}, $.jgrid.formatter.date);
if(!isUndefined(opts.colModel.formatoptions)) {
op = $.extend({}, op, opts.colModel.formatoptions);
}
return $.fmatter.util.DateFormat(op.srcformat,dt.toLocaleString(),op.newformat,op);
【问题讨论】: