jqGrid custom formatter
Posted
by great_llama
on Stack Overflow
See other posts from Stack Overflow
or by great_llama
Published on 2010-05-21T13:53:57Z
Indexed on
2010/05/21
18:20 UTC
Read the original article
Hit count: 1603
For one of the columns in my jqGrid, I'm providing a custom formatter function. I'm providing some special cases, but if those conditions aren't met, I'd like to resort to using the built-in date formatter utility method. It doesn't seem that I'm getting the right combination of $.extend() to create the options that method is expecting.
My colModel for this column:
{ 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"}
},
And an example of what I'm trying to do
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);
}
}
(An exception is being thrown in the guts of that DateFormat method, looks like where it's trying to read into a masks property of the options that get passed in)
EDIT:
The $.extend that put everything in the place it needed was getting it from that global property where the i18n library set it, $.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);
© Stack Overflow or respective owner