JQGRID显示空白而不是空

我正在使用JQGrid并且因为来自DB而在网格中显示Null。 我可以更改查询以返回空值。

但我尝试使用JQGrid处理。 如何用Grid中replace null by blank values

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

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

谢谢

最好处理这个服务器端,但是如果你想在jqGrid中执行它,你可以使用一个自定义格式化程序将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 }, ...], .... } 

我有同样的问题。

另外,我希望jqGrid用千位分隔符和2位小数显示我的数字,但是使用默认的'number'格式化程序会导致任何空值 (来自数据库)显示为“ 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. }