JQGRID显示空白而不是Null [英] JQGRID show blank instead of Null

查看:487
本文介绍了JQGRID显示空白而不是Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Am使用JQGrid并从数据库中获取Null并显示在网格中.我可以更改查询以返回空白值.

Am using JQGrid and am getting Null displayed in the grid as it comes from DB. I can change the query to return Blank value.

但是我尝试使用JQGrid进行处理.我如何replace null by blank values在网格中.

But am try to handle using JQGrid. How do i replace null by blank values in Grid.

我不想向用户显示NULL而是显示空白.

I don want to show NULL to users instead show blank.

我如何在JQGrid中实现这一目标?

How do i achieve this in JQGrid ?

谢谢

推荐答案

最好在服务器端进行处理,但是如果要在jqGrid中进行操作,则可以使用,所以我处理了两种情况):

It's probably best that you handle this server-side, but if you want to do it in jqGrid, you could use a custom formatter that converts null to the empty string. (I'm not sure if you are actually getting back the value null or the String "NULL", so I handled both cases):

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
    }, ...],
    ....
}

这篇关于JQGRID显示空白而不是Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆