jqGrid 将 NULL 数据显示为 "undefined"
jqGrid shows NULL data as "undefined"
来自服务器的数据为空值时遇到问题...在 jqGrid 中它们显示为 "undefined"。
我的数据源是服务器端 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),但这也不起作用。
知道我做错了什么吗?
我试过代码,但无法重现问题。参见 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
}
来自服务器的数据为空值时遇到问题...在 jqGrid 中它们显示为 "undefined"。
我的数据源是服务器端 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),但这也不起作用。
知道我做错了什么吗?
我试过代码,但无法重现问题。参见 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
}