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?

enter image description here

my jqgrid code

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());

         }

My Xml

<Response>
<isSuccess>true</isSuccess>
<operation>viewall</operation>
<message>No configurations were found for this project</message>
</Response>
AabinGunz
  • 12,109
  • 54
  • 146
  • 218
  • 1
    I suspect you're returning bad data. The jqGrid demos don't do this. Check the row count and page size you return. – Craig Stuntz Aug 17 '11 at 12:50
  • @Craig: I'll post my response from server next thing tomorrow morning. Thanks for your comment – AabinGunz Aug 17 '11 at 16:23
  • @Abhishek Simon: Could you include `jsonReader` definition in the jqGrid and the JSON data returned from the server? The problem described [here](http://stackoverflow.com/questions/3755396/jqgrid-pager-says-1-of-nan/3759439#3759439) is already fixed, but you have some very close problem. – Oleg Aug 17 '11 at 16:46
  • @Oleg: Hi Oleg, I updated my question with jqGrid code and xml response – AabinGunz Aug 18 '11 at 05:51

1 Answers1

2

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

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);

produce NaN value.

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;

to

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

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

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

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Please look at [this question](http://stackoverflow.com/questions/7357996/weird-behavior-of-jqgrid-row-selection) my multiselect is behaving in a weird manner – AabinGunz Sep 09 '11 at 09:08
  • @Abhishek Simon: I have seen your question, but I have to do other things now. Later after I find the time I will read your question und try to help you. – Oleg Sep 09 '11 at 09:12