3

I cant get jqGrid to show any records, my javascript:

jq.getScript("/js/grid.locale-en.js", function(){
    jq.getScript("/js/jquery.jqGrid.min.js", function(){
        jq(".normalTable").jqGrid({
            url:'/xml/results.xml',
            mtype: "GET",
            datatype: "xml",
            colNames: ['Instrument', 'ExpValue', 'BuyerPayout','SellerPayout'],
            colModel: [
                { name: 'Instrument', index: 'Instrument', width: 55, xmlmap: "Instrument" },
                { name: 'ExpValue', index: 'ExpValue', width: 80, xmlmap: "ExpValue" },
                { name: 'BuyerPayout', index: 'BuyerPayout', width: 80, xmlmap: "BuyerPayout" },
                { name: 'SellerPayout', index: 'SellerPayout', width: 80, xmlmap: "SellerPayout"}],
            pager: '#pager',
            rowNum: 10,
            rowList: [10, 20, 30],
            sortname: 'Instrument',
            viewrecords: true,
            gridview: true,
            autoencode: true,
            xmlReader: {
               root:"TradingResults",
               row:"TradingResult"
            },
            width: '480'
        });
    });
});

My XML structure:

<TradingResults>
    <DateGroup date="2014-04-24">
        <TradingResult>
            <Instrument>xyz</Instrument>
            <ExpValue>94.65</ExpValue>
            <BuyerPayout>0</BuyerPayout>
            <SellerPayout>100</SellerPayout>
        </TradingResult>
        <TradingResult>
            <Instrument>xyz</Instrument>
            <ExpValue>94.659</ExpValue>
            <BuyerPayout>0</BuyerPayout>
            <SellerPayout>100</SellerPayout>
        </TradingResult>
    </DateGroup>
<TradingResults>

No errors in console.

Result:

jqGrid empty grid

0

1 Answer 1

4
+50

you didn't set xml reader in your grid like.Grid need to expect xml

xmlReader: { repeatitems: false, root:"TradingResults",row:"TradingResult" }

and also set xmlmap for each column like

 { name: 'Instrument', index: 'Instrument', width: 55,xmlmap:"Instrument" },

Also did you include the DnR lib which is

<script src="grid/js/jqDnR.js" type="text/javascript">
</script>

This one is important

Update: Since this answer is getting much attention, here people may find additional information on jqgrid with xml data.

4
  • Thanks @janina, now the grid recognizes the number of rows, but now only displays an empty table: imgur.com/zuOzeZz
    – Sam T
    May 16, 2014 at 16:13
  • it made no difference, i still get an empty table. I also tried removing mType: "GET"
    – Sam T
    May 16, 2014 at 16:40
  • Solution in the end was: xmlReader: { repeatitems: false, root:"TradingResults", row:"TradingResult" } Please update your answer to include repeatitems: false
    – Sam T
    May 16, 2014 at 18:57
  • @Sam Thompson well done, u find the solution yourself May 16, 2014 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.