jqGrid将NULL数据显示为" undefined"

时间:2015-02-11 14:24:35

标签: jqgrid jqgrid-formatter

将来自服务器的数据作为空值出现问题...在jqGrid中它们显示为“未定义”。

我的数据源是服务器端XML,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
  <row id="0">
    <cell><![CDATA[0]]></cell>
    <cell><![CDATA[MENUBAR]]></cell>
    <cell><![CDATA[Main Menu]]></cell>
    <cell/>
    <cell/>
    <cell/>
    <cell><![CDATA[Y]]></cell>
    <cell><![CDATA[1]]></cell>
    <cell/>
    <cell/>
    <cell><![CDATA[1]]></cell>
  </row>
  <row id="1">
    <cell><![CDATA[1]]></cell>
    <cell><![CDATA[PCHN_MGT]]></cell>
    <cell><![CDATA[Channel Maanagement]]></cell>
    <cell/>
    <cell/>
    <cell/>
    <cell><![CDATA[Y]]></cell>
    <cell><![CDATA[1]]></cell>
    <cell/>
    <cell/>
    <cell><![CDATA[2]]></cell>
  </row>

注意空单元格值,这些是NULL。

这是我的jqGrid设置:

$(document).ready(function () {  
// Grid
$(function(){ 
  $("#list1").jqGrid({ 
    url:'!wspitm.P_PITM_LIST_XOUT',
    datatype: 'xml',
    editurl: "!wspitm.P_PITM_LIST_POST",
    gridview: true,
    mtype: 'GET',
    prmNames: {page:"page", rows:"rows", sort: "sidx", order: "sord", search:"isearch", nd:"nd", id:"id", oper:"oper", editoper:"edit", addoper:"add", deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"},
    pager: "#pager",
    rowNum: 10,
    rowList:[10,20,50],
    viewrecords: true,
    caption: 'Portal Item List',
    sortorder: "asc",
    width: "1100",
    height: "250",
    sortname: "WWBPITM_SURROGATE_ID",
colModel:[ 
{
name:"WWBPITM_SURROGATE_ID", 
align:"left", 
index:"WWBPITM_SURROGATE_ID", 
editable: false, 
edittype: "text", 
editrules: { required: false, edithidden: true }, 
formoptions: { label: "ID" }, 
formatter: "", 
label:"ID", 
sortable: true, 
width:15, 
classes: "" 
}
 ,
{
name:"WWBPITM_TITLE", 
align:"left", 
index:"WWBPITM_TITLE", 
editable: true, 
edittype: "text", 
editoptions: { size: 255 }, 
editrules: { required: true }, 
formoptions: { label: "Title" }, 
formatter: "", 
label:"Title", 
sortable: true, 
width:50, 
classes: "" 
}
 ,
{
name:"WWBPITM_SUBTITLE", 
align:"left", 
index:"WWBPITM_SUBTITLE", 
hidden: true, 
editable: true, 
edittype: "text", 
editoptions: { size: 255 }, 
editrules: { required: false }, 
formoptions: { label: "Sub-Title" }, 
formatter: "", 
label:"Sub-Title", 
sortable: true, 
width:75, 
classes: "" 
}

etc. etc.

我尝试使用自定义格式化程序将undefined转换为“”(如此JQGRID show blank instead of Null),但这也无效。

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:1)

我尝试了代码,但我无法重现问题。见the demo我强烈建议您删除formatter: "" 。它在构建每个单元格内容时产生异常,但显示的结果仍然可以。在colModel中包含不同可能属性的值非常糟糕。它不仅使代码不易读取,而且可能是不同错误的起源。列定义

{
    name:"WWBPITM_SURROGATE_ID", 
    align:"left", 
    index:"WWBPITM_SURROGATE_ID", 
    editable: false, 
    edittype: "text", 
    editrules: { required: false, edithidden: true }, 
    formoptions: { label: "ID" }, 
    formatter: "", 
    label:"ID", 
    sortable: true, 
    width:15, 
    classes: "" 
}

可以(并且应该)简化为以下

{
    name: "WWBPITM_SURROGATE_ID",
    label: "ID",
    width: 15
}