使用JQGrid
并在网格中显示Null,因为它来自数据库。我可以更改查询以返回空白值。
但我尝试使用JQGrid来处理。我如何在网格中replace null by blank values
。
我不想向用户显示NULL而是显示空白。
我如何在JQGrid中实现这一目标?
由于
答案 0 :(得分:6)
最好处理这个服务器端,但是如果你想在jqGrid中执行它,你可以使用custom formatter将null转换为空字符串。 (我不确定你是否真的回到了值null
或字符串"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
}, ...],
....
}
答案 1 :(得分:3)
我遇到了同样的问题。
另外,我希望jqGrid
用千位分隔符和2位小数显示我的数字,但使用默认的'number'
格式化程序导致任何 nulls (从数据库)到显示为" 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.
}