我想在网格上将日期显示为N / A,以防数据库中的日期为NULL或以正常日期格式显示。目前,我有以下代码:
name: 'Handshake_Actual_Date', index: 'Handshake_Actual_Date', search: false,
editable:true, align: "left", width: 75, formatter: "date", formatoptions:
{newformat:"m/d/Y" },
editoptions: {
size: 20,
dataInit: function (el) {
$(el).datepicker({ dateFormat: 'mm/d/yy' });
},
defaultValue: function () {
var currentTime = new Date();
var month = parseInt(currentTime.getMonth() + 1);
month = month <= 9 ? "0" + month : month;
var day = currentTime.getDate();
day = day <= 9 ? "0" + day : day;
var year = currentTime.getFullYear();
return day + "/" + month + "/" + year;
}
}
它工作得很好,但是我想要一个自定义格式器,如下所示:
function myFormatter (cellvalue, options, rowObject) {
if(cellvalue==null)
{
return "N/A";
}
else
{
return $.fn.fmatter.date(cellvalue, options, rowObject);
}
}
但它不起作用..!例如,您可以在此处查看代码:http : //jsfiddle.net/35Larwva/
尝试更换
$.fn.fmatter.date(cellvalue, options, rowObject)
到
$.fn.fmatter.call(this, "date", cellvalue, options, rowObject);
此外,我建议您使用更正确的JavaScript代码:cellvalue==NULL
应该替换为cellvalue === null
,您应该;
在语句末尾使用(return "N/A"
例如在语句之后),最好始终使用{}
forif
和else
语句。
更新:我修复了您的jqfiddle演示,使其现在可以正常工作:http : //jsfiddle.net/OlegKi/35Larwva/2/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句