JQGRID shows empty space instead of Null

I use JQGrid, and I get Null displayed in the grid, since it comes from the database. I can modify the request to return a null value.

But I am trying to handle JQGrid. How to make me replace null by blank valuesin the grid.

I do not want to show NULL to users, and not show empty.

How to achieve this in JQGrid?

thanks

+2
source share
2 answers

, , jqGrid, , null . ( , null String "NULL", ):

var nullFormatter = function(cellvalue, options, rowObject) {
    if(cellvalue === undefined || isNull(cellvalue) || cellvalue === 'NULL') {
        cellvalue = '';
    }

    return cellvalue;
}

$("#myGridContainer").jqGrid({
    ....
    colModel: [{
        label: 'Name',
        name:'name',
        index:'name',
        formatter:nullFormatter
    }, {
        label: 'Next Column',
        name:'nextCol',
        index:'nextCol',
        formatter: nullFormatter
    }, ...],
    ....
}
+6

.

, , jqGrid , 'number' NULL ( ), "0.00", .

$("#tblListOfRecords").jqGrid({
    ...
    colModel: [
      { name: "SomeNumber", formatter: 'number', sorttype: "integer", formatoptions: { decimalPlaces: 2 } }
    ]
    ...

, .

, :

$("#tblListOfRecords").jqGrid({
    ...
    colModel: [
      { name: "SomeNumber", formatter: formatNumber}
    ]
});

function formatNumber(cellValue, options, rowdata, action) {
    //  Convert a jqGrid number string (eg "1234567.89012") into a thousands-formatted string "1,234,567.89" with 2 decimal places
    if (cellValue == "")
        return "";
    if (cellValue == null || cellValue == 'null')
        return "";

    var number = parseFloat(cellValue).toFixed(2);          //  Give us our number to 2 decimal places
    return number.toLocaleString();                         //  "toLocaleString" adds commas for thousand-separators.
}
+3

All Articles