2011-09-09 152 views
0

我有这种非常不寻常的行为,让我来描述这个问题。jqGrid行选择的奇怪行为

的的jqGrid有14个记录中的所有一起,首先它被设置为rowNum:10,当从下拉我选择要显示50行中的所有记录容纳,但在Firefox 5当我选择11行(名称为asd)它也选择第10行。它在IE8中表现有所不同。

在IE8它给了我下面的错误

Webpage error details 

Message: 'className' is null or not an object 
Line: 2496 
Char: 4 
Code: 0 
URI: http://au1642163:10070/csm/view/include/js/jquery.jqGrid.min.js 

这里是IE8

enter image description here

我的jqGrid代码

var xml=client.responseText; 
     var xmlDoc = $.parseXML(xml); 
     var $xml = $(xml); 

     xml=xml.replace(/<productId>1/g, "<productId>"+productMap['1']); 
     xml=xml.replace(/<productId>2/g, "<productId>"+productMap['2']); 
$('#configDiv').empty(); 
      $('#configDiv').html(
        '<div id="configDetailsGrid" width="100%">' + 
        '<table id="list1" width="100%"></table><div id="gridpager"></div></div>'); 

      var grid = jQuery("#list1"); 
      var iconAlert; 

      getColumnIndexByName = function (grid, columnName) { 
       var cm = grid.jqGrid('getGridParam', 'colModel'), i = 0, l = cm.length; 
       for (; i < l; i += 1) { 
        if (cm[i].name === columnName) { 
         return i; // return the index 
        } 
       } 
       return -1; 
      }, 
      grid = jQuery("#list1"), 
      iconAlert = '<span class="ui-state-error" style="border:0"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span></span>'; 



      grid.jqGrid({ 

       datastr : xml, 
       datatype: 'xmlstring', 
       colNames:['cfgId','Name', 'Host','Operating System', 'Description','Product', 'Type', 'Last Updated Time','Last Updated By','',''], 
       colModel:[ 
        {name:'cfgId',index:'cfgId', width:90, align:"left", hidden:true}, 
        //{name:'updateDate',index:'updateDate', width:12, align:'center', formatter: oldConfigurationWarning }, 
        {name:'cfgName',index:'cfgName', width:70, align:"left", formatter: 'showlink', formatoptions: {baseLinkUrl: '#'} }, 
        {name:'hostname',index:'hostname', width:70, align:"left"}, 
        {name:'osname',index:'osname', width:90, align:"left"}, 
        {name:'cfgDesc',index:'cfgDesc', width:90, align:"left"}, 
        {name:'productId',index:'productId', width:40, align:"left"}, 
        {name:'cfgType',index:'cfgType', width:50, 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(); 
        } 

        //for showlink and icon alert having date difference more than 90 days 
        var iRow, row, trClasses, $cell, 
        icfgName = getColumnIndexByName(grid, 'cfgName'), 
        iupdateDate = getColumnIndexByName(grid, 'updateDate'), 

        mygrid = grid[0], 
        rows = mygrid.rows, 
        cRows = rows.length, 
        myLink = function (e) { 
         var $td = $(e.target).closest('td'), 
          text = $td.text(), 
          $tr = $td.closest('tr'), 
          rowid = $tr[0].id; 
          goToViewAllPage(rowid); 
        }; 

       for (iRow = 0; iRow < cRows; iRow += 1) { 
        row = rows[iRow]; // row.id is the rowid 
        trClasses = row.className.split(' '); 
        if ($.inArray('jqgrow', trClasses) > 0) { 
         // the row is a standard row (only if subGrid:true are used) 

         /*if ($(row.cells[iupdateDate]).text() === 'Science') { 
          $cell.prepend(iconAlert); 
         }*/ 
         var cellvalue1,firstDate,secondDate; 
         $cell = $(row.cells[icfgName]); 
         cellvalue1=$(row.cells[iupdateDate]).text(); 
         firstDate = new Date(); 
         //console.info(cellvalue1+", "+cellvalue1.length); 
         //var cellvalue1="08-18-2011 11:49:01"; 
         if(cellvalue1.length>25) 
         { 
          secondDate=new Date(); 
          //secondDate = secondDate.substring(0, secondDate.length-3); 

          if(diffOf2Dates(firstDate,secondDate,true)>=expireCondition) 
          { 
           $cell.prepend(iconAlert); 
          } 
          $cell.click(myLink); 
         } 
         else 
         { 

          secondDate = cellvalue1.substring(0, cellvalue1.length-6); 
          if(diffOf2Dates(firstDate,secondDate,false)>=expireCondition) 
          { 
           $cell.prepend(iconAlert); 
          } 
          $cell.click(myLink); 
         } 



        } 
       } 
       }, 
       onSelectRow: function(id,status){ 
        //var rowData = jQuery(this).getRowData(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响应的图像

<list> 
<Response> 
<cfgId>704</cfgId> 
<cfgName>IIR Windows1</cfgName> 
<cfgDesc>asda</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientIIR.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientIIR.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>IIR</hostname> 
<createDate>2011-09-07 10:55:31.0 IST</createDate> 
<updateDate>2011-09-07 10:55:31.0 IST</updateDate> 
<state>1</state> 
<productId>1</productId> 
<osname>Windows_NT</osname> 
</Response> 
<Response> 
<cfgId>717</cfgId> 
<cfgName>ilmwin</cfgName> 
<cfgDesc>asd</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientin164302.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientin164302.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>IN164302</hostname> 
<createDate>2011-09-07 16:45:03.0 IST</createDate> 
<updateDate>2011-09-07 16:45:03.0 IST</updateDate> 
<state>1</state> 
<productId>2</productId> 
<osname>Windows_NT</osname> 
</Response> 
<Response> 
<cfgId>718</cfgId> 
<cfgName>ilmwin1</cfgName> 
<cfgDesc>asdasd</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientin164302.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientin164302.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>IN164302</hostname> 
<createDate>2011-09-07 16:46:35.0 IST</createDate> 
<updateDate>2011-09-08 10:19:26.0 IST</updateDate> 
<state>2</state> 
<productId>2</productId> 
<osname>Windows_NT</osname> 
</Response> 
<Response> 
<cfgId>723</cfgId> 
<cfgName>ilm linux</cfgName> 
<cfgDesc>asd</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientestilo.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientestilo.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>estilo</hostname> 
<createDate>2011-09-08 14:20:09.0 IST</createDate> 
<updateDate>2011-09-08 14:20:09.0 IST</updateDate> 
<state>1</state> 
<productId>2</productId> 
<osname>Linux</osname> 
</Response> 
<Response> 
<cfgId>696</cfgId> 
<cfgName>ILMwin1</cfgName> 
<cfgDesc>asfas</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientin164302.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientin164302.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>IN164302</hostname> 
<createDate>2011-09-06 16:15:06.0 IST</createDate> 
<updateDate>2011-09-06 16:15:06.0 IST</updateDate> 
<state>1</state> 
<productId>2</productId> 
<osname>Windows_NT</osname> 
</Response> 
<Response> 
<cfgId>697</cfgId> 
<cfgName>ILMlin</cfgName> 
<cfgDesc>dgds</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientestilo.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientestilo.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>estilo</hostname> 
<createDate>2011-09-06 16:20:58.0 IST</createDate> 
<updateDate>2011-09-06 16:20:58.0 IST</updateDate> 
<state>1</state> 
<productId>2</productId> 
<osname>Linux</osname> 
</Response> 
<Response> 
<cfgId>706</cfgId> 
<cfgName>ILM linux</cfgName> 
<cfgDesc>wwrwrwr</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientestilo.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientestilo.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>estilo</hostname> 
<createDate>2011-09-07 14:22:03.0 IST</createDate> 
<updateDate>2011-09-07 14:22:03.0 IST</updateDate> 
<state>1</state> 
<productId>2</productId> 
<osname>Linux</osname> 
</Response> 
<Response> 
<cfgId>698</cfgId> 
<cfgName>test1</cfgName> 
<cfgDesc>asfta</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientgcslpar1.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientgcslpar1.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>gcslpar1</hostname> 
<createDate>2011-09-06 17:14:31.0 IST</createDate> 
<updateDate>2011-09-08 10:20:15.0 IST</updateDate> 
<state>2</state> 
<productId>1</productId> 
<osname>AIX</osname> 
</Response> 
<Response> 
<cfgId>699</cfgId> 
<cfgName>test2</cfgName> 
<cfgDesc>adAD</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientgcslpar2.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientgcslpar2.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>gcslpar2</hostname> 
<createDate>2011-09-06 17:14:46.0 IST</createDate> 
<updateDate>2011-09-06 17:14:46.0 IST</updateDate> 
<state>1</state> 
<productId>1</productId> 
<osname>AIX</osname> 
</Response> 
<Response> 
<cfgId>702</cfgId> 
<cfgName>IIR Windows</cfgName> 
<cfgDesc>asdad</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientIIR.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientIIR.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>IIR</hostname> 
<createDate>2011-09-07 10:47:10.0 IST</createDate> 
<updateDate>2011-09-07 10:47:10.0 IST</updateDate> 
<state>1</state> 
<productId>1</productId> 
<osname>Windows_NT</osname> 
</Response> 
<Response> 
<cfgId>687</cfgId> 
<cfgName>asd</cfgName> 
<cfgDesc>a</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientestilo.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientestilo.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>estilo</hostname> 
<createDate>2011-09-06 13:28:28.0 IST</createDate> 
<updateDate>2011-09-06 13:28:28.0 IST</updateDate> 
<state>1</state> 
<productId>1</productId> 
<osname>Linux</osname> 
</Response> 
<Response> 
<cfgId>688</cfgId> 
<cfgName>asd1</cfgName> 
<cfgDesc>asd</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientbuckeye.ABC.com.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientbuckeye.ABC.com.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>buckeye.ABC.com</hostname> 
<createDate>2011-09-06 13:30:10.0 IST</createDate> 
<updateDate>2011-09-06 13:30:10.0 IST</updateDate> 
<state>1</state> 
<productId>1</productId> 
<osname>Linux</osname> 
</Response> 
<Response> 
<cfgId>701</cfgId> 
<cfgName>NULL</cfgName> 
<cfgDesc>asda</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientin164302.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientin164302.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>IN164302</hostname> 
<createDate>2011-09-07 10:43:19.0 IST</createDate> 
<updateDate>2011-09-08 16:44:00.0 IST</updateDate> 
<state>2</state> 
<productId>2</productId> 
<osname>Windows_NT</osname> 
</Response> 
<Response> 
<cfgId>705</cfgId> 
<cfgName>Sunos config</cfgName> 
<cfgDesc>asdasd</cfgDesc> 
<cfgType>Production</cfgType> 
<fileName>csmclientzenvo.xml</fileName> 
<absolutePath>../webapps/csm/files//12345/csmclientzenvo.xml</absolutePath> 
<emailAddress>[email protected]</emailAddress> 
<projectId>12345</projectId> 
<hostname>zenvo</hostname> 
<createDate>2011-09-07 11:22:56.0 IST</createDate> 
<updateDate>2011-09-07 11:22:56.0 IST</updateDate> 
<state>1</state> 
<productId>1</productId> 
<osname>SunOS</osname> 
</Response> 
</list> 

回答

1

你应该自己测试你发布的代码。您应该仔细阅读the question with the answer。如果你不想有所描述的问题,你应该以另一种方式设置你的问题。不过,我会回答你目前的问题。

当前代码包含许多未定义的函数和变量。而且它有小的语法错误。其中一个最重要的是

var grid = jQuery("#list1"); 
var iconAlert; 

getColumnIndexByName = function (grid, columnName) { 
    ... 
}, 
grid = jQuery("#list1"), 
iconAlert = '<span class="ui-state-error" ...' 

你不应该两次定义相同的变量,并且以任何方式取代';'在var iconAlert;处用逗号来定义作为函数的变量getColumnIndexByName

开头(xml=xml.replace(/<productId>1/g, "<productId>"+productMap['1']);)我不明白,在所有的代码。为什么您需要对XML进行奇怪的修改(如果有$xml),并且可以使用jQuery来选择和修改任何XML元素。

如果你想继续使用这么脏代码,你可以有更严重的问题。我建议你总是在JSLint验证你的代码。您可以包括例如

/*global $, jQuery */ 
/*jslint devel: true, browser: true, vars: true, white: true, plusplus: true*/ 

JSLint的选择,毕竟与准备测试例子仅the resulting code没有您所描述的问题的工作。

+0

感谢有关禁止用户的头,我会记住这一点。 – abi1964

+0

@Abhishek西蒙:欢迎您! – Oleg