在jqgrid的0行上,我们如何将NaN的Page 1替换为其他内容? [英] On 0 row in jqgrid how can we replace Page 1 of NaN to something else?

查看:96
本文介绍了在jqgrid的0行上,我们如何将NaN的Page 1替换为其他内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果jqgrid有时没有任何行,则显示Page 1 of NaN这里的Nan是什么?我们不能将其更改为更合适的内容,例如Page 0 of 0还是更好的东西?

if the jqgrid has no rows at some time, it shows Page 1 of NaN what is Nan here? can't we change it to something more appropriate like Page 0 of 0 or something better?

我的jqgrid代码

var grid = jQuery("#list1");


                grid.jqGrid({

                  datastr : xml,
                  datatype: 'xmlstring',
                  colNames:['cfgId','Name', 'Host', 'Description','Product', 'Type', 'Last Updated Time','Last Updated By','',''],
                  colModel:[
                      {name:'cfgId',index:'cfgId', width:90, align:"left", hidden:true},
                      {name:'cfgName',index:'cfgName', width:90, align:"left", formatter: 'showlink', formatoptions:
                                                                                {
                                                                                    baseLinkUrl:'javascript:',
                                                                                    showAction: "goToViewAllPage('",
                                                                                    addParam: "');"

                                                                                }},
                      {name:'hostname',index:'hostname', width:90, align:"left"},
                      {name:'cfgDesc',index:'cfgDesc', width:90, align:"left"},
                      {name:'productId',index:'productId', width:60, align:"left"},
                      {name:'cfgType',index:'cfgType', width:60, align:"left"},
                      {name:'updateDate',index:'updateDate',sorttype:'Date', width:120, align:"left"},
                      {name:'emailAddress',index:'emailAddress', width:120, align:"left"},
                      {name:'absolutePath',index:'absolutePath', width:90, align:"left", hidden:true},
                      {name:'fileName',index:'fileName', width:90, align:"left", hidden:true},
                  ],
                  pager : '#gridpager',
                  rowNum:10,
                  rowList:[10,50,100],
                  scrollOffset:0,
                  height: 'auto',
                  emptyrecords: 'No configurations loaded',
                  autowidth:true,
                  viewrecords: true,
                  gridview: true,
                  multiselect: true,
                  xmlReader: {
                      root : "list",
                      row: "Response",
                      userdata: "userdata",
                      repeatitems: false
                  },
                  loadComplete: function () {
                        var count = grid.getGridParam();
                        var ts = grid[0];
                        if (ts.p.reccount === 0) {
                            grid.hide();
                            emptyMsgDiv.show();
                        } else {
                            grid.show();
                            emptyMsgDiv.hide();
                        }
                    },
                  onSelectRow: function(id,status){
                      var rowData = jQuery(this).getRowData(id); 
                      configid = rowData['cfgId'];
                      configname=rowData['cfgName'];
                      configdesc=rowData['cfgDesc'];
                      configenv=rowData['cfgType'];
                      absolutepath=rowData['absolutePath'];

                      /*filename=rowData['fileName'];
                      updatedate=rowData['updateDate'];
                      absolutepath=rowData['absolutePath'];*/
                      updateproductid=rowData['productId'];


                      $('#cfgid').removeAttr('disabled');
                      document.getElementById("cfgid").value=configid;
                      document.getElementById("cfgname").value=configname;
                      document.getElementById("cfgdesc").value=configdesc;

                      var element = document.getElementById('cfgenv');
                      if(configenv=="Production")
                          element.value = "Production";
                      else if(configenv=="Development")
                          element.value="Development";
                      else
                          element.value="Test/QA";
                      rowChecked=1;
                      currentrow=id;
                      }


                });
                grid.jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false});
                jQuery("#m1").click( function() {
                    var s;
                    s = grid.jqGrid('getGridParam','selarrrow');
                    alert(s);
                });
                var myGrid = $("#list1");
                $("#cb_"+myGrid[0].id).hide();
                // place div with empty message insde of bdiv
                emptyMsgDiv.insertAfter(grid.parent());

         }

我的Xml

<Response>
<isSuccess>true</isSuccess>
<operation>viewall</operation>
<message>No configurations were found for this project</message>
</Response>

推荐答案

It's the same problem which was described here, but with XML data.

该行中变量rn将被声明,但不会为其分配任何值.值rn = parseInt(ts.p.rowNum,10);的第一个赋值为此处if(gxml && gl)内部(在您的情况下为false).因此该语句

In the line the variable rn will be declared, but it will be not assigned it any value. The first assignment of the value rn = parseInt(ts.p.rowNum,10); will be here inside of if(gxml && gl) which is false in your case. So the statement

ts.p.lastpage = Math.ceil(gl/ rn);

产生NaN值.

要修复该错误,您可以从以下位置修改jqGrid 4.1.2的jquery.jqGrid.src.js的1086行:

To fix the bug you can modify the line 1086 of the jquery.jqGrid.src.js of the jqGrid 4.1.2 from

var gl = gxml.length, j=0, grpdata={}, rn;

var gl = gxml.length, j=0, grpdata={}, rn = parseInt(ts.p.rowNum,10);

包含相同分配的行1088可以删除.

The line 1088 which contains the same assignment can be removed.

您如何在该演示(与您使用相同的代码使用原始的jquery.jqGrid.src.js),这些更改可以解决问题.

How you can see in the demo (compare with your same code used original jquery.jqGrid.src.js) the changes fix the problem.

这篇关于在jqgrid的0行上,我们如何将NaN的Page 1替换为其他内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆