對於我的jqGrid中的其中一列,我提供了一個自定義格式化函數。我提供了一些特殊情況,但如果不滿足這些條件,我想使用內置的日期格式化工具方法。我似乎沒有得到$ .extend()的正確組合來創建方法所期望的選項。jqGrid自定義格式化程序
我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);
是的,似乎我不得不從i18n格式化選項延伸,發現正確的組合。謝謝! – 2010-05-21 18:13:39
不客氣,很高興幫助:) – 2010-05-21 18:37:14