Javascript 如何在jqGrid中添加行,这也有一个复选框

Javascript 如何在jqGrid中添加行,这也有一个复选框,javascript,jqgrid,Javascript,Jqgrid,我正在用下面的代码添加到我的jqgrid中,除了cfgname和updateDate之外的所有代码都显示在我的网格中,这里有什么问题 function addRow(cfgid,cfgname,hostname,cfgDesc,productId,cfgType,updateDate,emailAddress,absolutePath) { console.info(cfgid+", "+cfgname+", "+hostname+", "+cfgDesc+", "+productId+", "

我正在用下面的代码添加到我的jqgrid中,除了
cfgname
updateDate
之外的所有代码都显示在我的网格中,这里有什么问题

function addRow(cfgid,cfgname,hostname,cfgDesc,productId,cfgType,updateDate,emailAddress,absolutePath)
{
console.info(cfgid+", "+cfgname+", "+hostname+", "+cfgDesc+", "+productId+", "+cfgType+", "+updateDate+", "+emailAddress+", "+absolutePath);
var myrow = {cfgid:cfgid, '':'', cfgname:cfgname, hostname:hostname, cfgDesc:cfgDesc, productId:productId,hostname:hostname,cfgType:cfgType,emailAddress:emailAddress,absolutePath:absolutePath};
$("#list1").addRowData("1", myrow);
$("#list1").trigger("reloadGrid");
}

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:"right", hidden:true},
                  {name:'',index:'', width:15, align:"right",edittype:'checkbox',formatter: "checkbox",editoptions: { value:"True:False"},editable:true,formatoptions: {disabled : false}},
                  {name:'cfgName',index:'cfgName', width:90, align:"right"},
                  {name:'hostname',index:'hostname', width:90, align:"right"},
                  {name:'cfgDesc',index:'cfgDesc', width:90, align:"right"},
                  {name:'productId',index:'productId', width:60, align:"right"},
                  {name:'cfgType',index:'cfgType', width:60, align:"right"},
                  {name:'updateDate',index:'updateDate', width:120, align:"right"},
                  {name:'emailAddress',index:'emailAddress', width:120, align:"right"},
                  {name:'absolutePath',index:'absolutePath', width:90, align:"right", hidden:true},
              ],
              pager : '#gridpager',
              rowNum:10,
              scrollOffset:0,
              height: 'auto',

              autowidth:true,
              viewrecords: true,
              gridview: true,
              xmlReader: {
                  root : "list",
                  row: "com\\.abc\\.db\\.ConfigInfo",
                  userdata: "userdata",
                  repeatitems: false
              },
              onSelectRow: function(id,status){
                  var rowData = jQuery(this).getRowData(id); 
                  configid = rowData['cfgId'];
                  /*configname=rowData['cfgName'];
                  configdesc=rowData['cfgDesc'];
                  configenv=rowData['cfgType'];
                  filename=rowData['fileName'];
                  updatedate=rowData['updateDate'];
                  absolutepath=rowData['absolutePath'];*/
                  if(status==true)
                  {

                  }

                  rowChecked=1;
                  currentrow=id;
                  }
}
               }

            });
            grid.jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false});
这是一张快照


您的代码中有一些错误

第一个错误:在填充
myrow={…}
时,设置了
cfgname:cfgname
而不是
cfgname:cfgname
(网格中的列具有
名称:'cfgname'
属性,而不是
名称:'cfgname'


第二个错误:您只显示
updateDate
console.info
相关的
updateDate,但没有设置
myrow
的属性
updateDate:updateDate

,谢谢,我太傻了。另外,我希望添加的行显示为第一行,我如何才能做到这一点?有没有像设置行这样的方法,或者我必须根据
updateDate
对其进行排序?另外,如果我必须排序,我怎么能在这个日期排序?@Ricky:不客气!您使用的方法可以与两个以上的参数一起使用。第三个参数定义添加行的位置。在您的情况下,可以使用
'first'
字符串。其他可能的值:
'last'
(默认值)、
'after'
'before'
。如果使用最后两个值中的一个,则应使用要添加新行的前后行的
id
定义
addRowData
的第4个参数。我尝试了
$(“#list1”)。addRowData(“1”,myrow,“first”)但它仍然在末尾添加,当我单击新添加的行时,第一行被选中