开发者

How to map an xml in jqGrid?

开发者 https://www.devze.com 2023-03-14 05:22 出处:网络
I am using jqGrid, I have a given xml which i want to be mapped to jqGrid <list> <com.abc.db.ConfigInfo>

I am using jqGrid, I have a given xml which i want to be mapped to jqGrid

<list>
<com.abc.db.ConfigInfo>
<cfgId>83</cfgId>
<cfgName>test</cfgName>
<cfgDesc>test</cfgDesc>
<cfgType>test</cfgType>
<fileName>csmclientbenz.xml</fileName>
<absolutePath>../webapps/csm/files//1-105101/csmclientbenz.xml</absolutePath>
<emailAddress>abhishek@abc.com</emailAddress>
<projectId>1-105101</projectId>
<hostname>benz</hostname>
<createDate>2011-06-15 15:29:55.0 IST</createDate>
<updateDate>2011-06-15 15:29:55.0 IST</updateDate>
<state>1</state>
<productId>1</productId>
</com.abc.db.ConfigInfo>
<com.abc.db.ConfigInfo>
<cfgId>102</cfgId>
<cfgName>cfgname1</cfgName>
<cfgDesc>test</cfgDesc>
<cfgType>test</cfgType>
<fileName>csmclientestilo.xml</fileName>
<absolutePath>../webapps/csm/files//1-105101/csmclientestilo.xml</absolutePath>
<emailAddress>abhishek@abc.com</emailAddress>
<projectId>1-105101</projectId>
<hostname>estilo</hostname>
<createDate>2011-06-20 18:26:03.0 IST</createDate>
<updateDate>2011-06-20 18:26:03.0 IST</updateDate>
<state>1</state>
<productId>1</productId>
</com.abc.db.ConfigInfo>
</list>

I used something like this, but please help me move from here, how shall i assign xml which comes from XMLHttpRequest to jqGrid

var xml=client.responseT开发者_高级运维ext;
         $('#configDiv').empty();
            $('<div width="100%">')
            .attr('id','configDetailsGrid')
            .html('<table id="list1" width="100%"></table>'+
                    '<div id="gridpager"></div>'+
                '</div>')       
            .appendTo('#configDiv');    

            jQuery("#list1").jqGrid({
                datatype: "clientSide",
                height: 250,
                colNames:['cfgId','cfgName', 'cfgDesc', 'cfgType','absolutePath', 'updateDate', 'fileName'],
                colModel:[
                    {name:'cfgId',index:'cfgId', width:90, align:"right"},
                    {name:'cfgName',index:'cfgName', width:90, align:"right"},
                    {name:'cfgDesc',index:'cfgDesc', width:90, align:"right"},
                    {name:'cfgType',index:'cfgType', width:90, align:"right"},
                    {name:'absolutePath',index:'absolutePath', width:90, align:"right"},
                    {name:'updateDate',index:'updateDate', width:90, align:"right"},
                    {name:'fileName',index:'fileName', width:90, align:"right"},
                ],
                pagination:true,
                pager : '#gridpager',
                rowNum:10,
                scrollOffset:0,
                height: 'auto',
                autowidth:true,
                viewrecords: true,
                gridview: true,
 xmlReader: { 
                    root : "list",
                    row: "com.abc.db.ConfigInfo",
                    repeatitems: false,
                    id: "ASIN"
                    },
                edit:false,
                add:false,
                del:false

            });

Later I also need to hide cfgid and filename. Thanks please help


You have special character '.' (point) in the name of XML node, so you have to escape the character like so:

row: "com\\.abc\\.db\\.ConfigInfo"

Moreover you data has nodes and not attributes, so you don't need convert the data before it can be read by jqGrid. So the following code will use the XML data directly:

jQuery('#list').jqGrid({
  url: 'Ricky.xml',
  datatype: 'xml',
  colNames:['cfgId','cfgName', 'cfgDesc', 'cfgType','absolutePath', 'updateDate', 'fileName'],
  colModel:[
      {name:'cfgId',index:'cfgId', width:90, align:"right"},
      {name:'cfgName',index:'cfgName', width:90, align:"right"},
      {name:'cfgDesc',index:'cfgDesc', width:90, align:"right"},
      {name:'cfgType',index:'cfgType', width:90, align:"right"},
      {name:'absolutePath',index:'absolutePath', width:90, align:"right"},
      {name:'updateDate',index:'updateDate', width:90, align:"right"},
      {name:'fileName',index:'fileName', width:90, align:"right"},
  ],
  pager : '#pager',
  rowNum:10,
  scrollOffset:0,
  height: 'auto',
  autowidth:true,
  viewrecords: true,
  gridview: true,
  xmlReader: {
      root : "list",
      row: "com\\.abc\\.db\\.ConfigInfo",
      repeatitems: false
  }
});

See the working demo.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号