Note that there are some explanatory texts on larger screens.

plurals
  1. POjqGrid custom formatter
    text
    copied!<p>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.</p> <p>My colModel for this column:</p> <pre><code>{ 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"} }, </code></pre> <p>And an example of what I'm trying to do</p> <pre><code>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); } } </code></pre> <p>(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)</p> <p><strong>EDIT:</strong></p> <p>The $.extend that put everything in the place it needed was getting it from that global property where the i18n library set it, <strong>$.jgrid.formatter.date</strong>.</p> <pre><code>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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload