I want to diplay date on grid as N/A incase it is NULL in the database, or else in normal date format. At present I have this code:
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;
}
}
It works perfectly well but I want a custom formatter like below :
function myFormatter (cellvalue, options, rowObject) {
if(cellvalue==null)
{
return "N/A";
}
else
{
return $.fn.fmatter.date(cellvalue, options, rowObject);
}
}
but it is not working..! for an example you can see the code here : http://jsfiddle.net/35Larwva/
Try to replace
to
Moreover I recommend you to use more correct JavaScript code:
cellvalue==NULL
should be replaced tocellvalue === null
, you should use;
at the end of statements (afterreturn "N/A"
for example) and it's better always use{}
forif
andelse
statements.UPDATED: I fixed your jqfiddle demo so that it work now: http://jsfiddle.net/OlegKi/35Larwva/2/