Blank when NaN in jqGrid cells

佐手、 提交于 2019-12-07 03:46:05

问题


How to set blank instead of NaN in jqGrid cells ? Using formatter ? Is there an example?


回答1:


This is REALLY old but the jqGrid documentation didn't have an easy answer and this question pulls up first in Google results when I was looking for the same answer.

I was able to display a blank cell instead of a 0 when using the predefined formatter option for an integer using this code:

{ name: 'Quantity', formatter: 'integer', formatoptions: { defaultValue: ''} }

The defaultValue is just set to blank.




回答2:


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);
};



回答3:


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)


来源:https://stackoverflow.com/questions/1775776/blank-when-nan-in-jqgrid-cells

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!