How to set blank instead of NaN in jqGrid cells ? Using formatter ? Is there an example?
A:
On the server, before you return your data as XML/JSON/whatever, try setting DBNull values equal to a blank string.
Alternatively, if it is acceptable to display NULL values as 0, you could modify your SQL along these lines:
SELECT IsNull(my_amount, 0)
Justin Ethier
2009-11-22 16:15:49
I think that the solution is in the formatter option of colmodel. There are two ways: Predefined and Custom formatter. In my case, i want to use the predefined 'currency' formatter, but with the possibility to return blank instead of 'NaN' when value is null. It seems that there is no way to avoid rewriting my custum currency formatter function.Thank you again Justin.
raouf
2009-11-22 17:35:42
No problem, good luck!
Justin Ethier
2009-11-22 18:13:34
A:
I would not rewrite the custom formatter -- but override it (or make a new one)! That way, when a new version of jQgrid comes out, you don't overwrite your custom wrapper.
For example, my users don't want to see the value if it is 0, so I do this:
$.fn.fmatter.currency = function (cellval, opts) {
if (cellval == 0) {
return '';
}
var op = $.extend({},opts.currency);
if(!isUndefined(opts.colModel.formatoptions)) {
op = $.extend({},op,opts.colModel.formatoptions);
}
if(isEmpty(cellval)) {
return op.defaultValue;
}
return $.fmatter.util.NumberFormat(cellval,op);
};
But I could also call it:
$.fn.fmatter.currencyNoZero
In your case, I would do this:
$.fn.fmatter.currency = function (cellval, opts) {
if (cellval == null) {
return '';
}
var op = $.extend({},opts.currency);
if(!isUndefined(opts.colModel.formatoptions)) {
op = $.extend({},op,opts.colModel.formatoptions);
}
if(isEmpty(cellval)) {
return op.defaultValue;
}
return $.fmatter.util.NumberFormat(cellval,op);
};
Stephen J. Fuhry
2009-12-08 14:05:56