سؤال

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

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top