1

I tried using jqGrid but it only maps xml node text. I have given my xml below where I need to use xpath or similar to show filesystem content in it, with proper variable pagination, filtering, sort and selection of particular row.

<?xml-stylesheet type="text/xsl" href="csmclientiir.xsl"?>
<csmclient product="abc"   date="4/26/11 2:05 PM">
<system>
    <osname>Linux
    </osname>
    <hostname>AbhishekNix
    </hostname>
    <release>2.6.18-128.el5
    </release>
    <filesystem>
        <file mount='/home/hp1' home='(innfs2:/vol/home/shome/home/hp1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/par21' home='(innfs2:/vol/home/shome/home/par21)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/h231' home='(innfs2:/vol/home/shome/home/h231)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/avallin1' home='(innfs2:/vol/home/shome/home/avallin1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/park' home='(innfs2:/vol/home/shome/home/park)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/sp1' home='(innfs2:/vol/home/shome/home/sp1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/ganga1' home='(innfs2:/vol/home/shome/home/ganga1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/nbp1' home='(innfs2:/vol/home/shome/home/nbp1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
    </filesystem>
</system>
<product>
    <showtime>Tue Apr 26 14:05:23 2011
    </showtime>
</product>
</csmclient>

I am also providing the code that I used for jqGrid, which only shows header

jQuery("#listTable").jqGrid({
    url: cpath, 
    datatype: "xml",
    colNames:["Total Space","Free Space","Used Space", "Used Percentage"], 
    colModel:[ {name:"Total Space",index:"Total Space", width:90, xmlmap:"system>filesystem>file>@total"},
               {name:"Free Space",index:"Free Space", width:120, xmlmap:"system>filesystem>file>@free"},
               {name:"Used Space",index:"Used Space", width:180,xmlmap:"system>filesystem>file>@used"},
               {name:"Used Percentage",index:"Used Percentage", width:100, align:"right",xmlmap:"system>filesystem>file>@percentage", sorttype:"float"}
             ],
    height:250,
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30], 
    viewrecords: true, 
    gridview: true,
    loadonce: true, 
    xmlReader: { 
        root : "csmclient",
        row: "system>filesystem",
        repeatitems: false,
        id: "ASIN"
        },
    caption: "Disk Usage"
    });
AabinGunz
  • 12,109
  • 54
  • 146
  • 218

1 Answers1

0

As per the docs:

XML Notes and Limitations

Attributes in any XML tag can not be used to obtain the data. The only exception is the id

You will have to transform the XML into a format compatible with jqGrid. I would use XSLT.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Can't I use jquery xml parser to transform each `file` into a data supported by `jqGrid`? if yes can you help me with it, even an example for XSLT would be good, also I need variable pagination, filter and sorting – AabinGunz Jun 17 '11 at 16:08
  • Yes, you can use jQuery to restructure the XML. It's just like manipulating the HTML DOM except that you don't start with a selector like `$('#myElement')`, you start with an XML string like `var xml = '`;` and then jQueryify it: `$(xml)`. – Matt Ball Jun 17 '11 at 16:11
  • @Abhishek: [addXmlData](https://github.com/tonytomov/jqGrid/blob/v4.1.0/js/grid.base.js#L1023) method used by jqGrid to read XML data is not so flexible as `addJSONData` for example. It uses constructs like `this.textContent || this.text` or in other places `this.getAttribute("name")` (see [here](https://github.com/tonytomov/jqGrid/blob/v4.1.0/js/grid.base.js#L1066) or [here](https://github.com/tonytomov/jqGrid/blob/v4.1.0/js/grid.base.js#L1103)). So in the most cases you can't use attributes. So you have to convert your XML data in any way to make it jqGrid compatible. – Oleg Jun 17 '11 at 19:33
  • @Oleg: I am a beginner please bear with me, So 1st i'll send a request to get my xml data, convert that xml data to some equivalent array, 3rd i'll use this array to create jqGrid. Is that correct? If yes can you provide me a structure of the array which I can build. Thanks – AabinGunz Jun 18 '11 at 04:07
  • 1
    @Abhishek: The best if the server will produce the server response in another format: XML without attributes for the table rows or better JSON format. You can find in [the documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data) more information. The server should additionally post back only one page of data requested by the client. See [here](http://stackoverflow.com/questions/5764709/jqgrid-not-loading-data/5766189#5766189) for additional information about paging. – Oleg Jun 18 '11 at 06:13