JQGRID 显示空白而不是 Null [英] JQGRID show blank instead of Null
问题描述
我正在使用 JQGrid
并在网格中显示 Null,因为它来自 DB.我可以更改查询以返回空白值.
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 来处理.我如何在 Grid 中用空白值替换 null
.
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 中处理,你可以使用 自定义格式化程序,将 null 转换为空字符串.(我不确定你是否真的取回了值 null
或字符串 "NULL"
,所以我处理了这两种情况):
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屋!