English 中文(简体)
Blank when NaN in jqGrid cells
原标题:

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

问题回答

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.

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

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)




相关问题
JavaScript is a NaN, but I know it s not?

I have the following two functions... function splitTitleString(titleText) { var titleText = titleText; var temp = new Array(); temp = titleText.split( - ); var now = new Date()....

Column total NAN error

I am using this bit of code to add the values in a table column which works pretty well until it encounters a null td cell with a   value. From that point on in the loop, I receive a NaN error ...

In Javascript, how to avoid NaN when adding arrays

I m trying to add the values of two arrays in javascript eg. [1,2,1] + [3,2,3,4] The answer should be 4,4,4,4 but I m either getting 4,4,4 or 4,4,4,NaN if I change the 1st array length to 4. I ...

Java MDSJ produces NaN

Anyone have any experience with MDSJ? The following input produces only NaN results and I can t figure out why. The documentation is pretty sparse. import mdsj.Data; import mdsj.MDSJ; public class ...

Break on NaNs or infs

It is often hard to find the origin of a NaN, since it can happen at any step of a computation and propagate itself. So is it possible to make a C++ program halt when a computation returns NaN or inf? ...

NaN problem in Java

I am converting four bytes to float and I m getting NaN as a result, but I want the value 0.0. What am I doing wrong? This is my code: public class abc { public static void main(String[] args) ...

Why does Assert.AreEqual(1.0, double.NaN, 1.0) pass?

Short question, why does Assert.AreEqual(1.0, double.NaN, 1.0) pass? Whereas Assert.AreEqual(1.0, double.NaN) fails. Is it a bug in MSTest (Microsoft.VisualStudio.QualityTools.UnitTestFramework) or ...

Blank when NaN in jqGrid cells

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

热门标签