无法使用xml在网格中显示数据

时间:2015-07-27 09:31:51

标签: jquery jqgrid

我正在尝试在jqGrid中显示基于xml的数据。我在网格中的许多地方使用jqGrid,它可以使用我之前的xml数据。

唯一的区别在于xml。当前的xml包含不同的标记。



$("#uxData").jqGrid({
        url: ServiceUrl,
        datatype: 'xml',
        mtype: 'GET',
        colNames: ['CardCode'],
        colModel: [
            { name: 'CardCode', index: 'CardCode', sortable: true, align: "left", width: 100, search: true }
        ],
        loadError: function (xhr, status, error) {
            $(this).HideBusy();
            alert(xhr.responseText);
        },
        loadComplete: function (data) {
            $("#Window").dialog('open');
            $(this).HideBusy();
            debugger;
        },
        serializeGridData: function (postData) {
            if (postData.searchField === undefined) postData.searchField = null;
            if (postData.searchString === undefined) postData.searchString = null;
            if (postData.searchOper === undefined) postData.searchOper = null;
            if (postData.filters === undefined) postData.filters = null;
            return (postData);
        },
        ondblClickRow: function (rowid, iRow, iCol, e) {
            //debugger;
            //var SelectedRow = $("#ListOfBP1").jqGrid('getRowData', rowid, 'selrow');

            //$("#uxCardCode").val(SelectedRow.CardCode);
            //$("#Text4").val(SelectedRow.CardName);
            $("#Window").dialog('close');
        },
        xmlReader: {
             repeatitems: false,
             total: "Root>total",
             page: "Root>page",
             records: "Root>records",
             rows: "Root>rows>DocumentElement>data"
        },
        pager: 'rptParamPager',
        rowNum: 5,
        viewrecords: true,
        gridview: true,
        rownumbers: true,
        height: 440,
        width: 900
    }).trigger('reloadGrid');




<Root>
    <total>161</total>
    <page>1</page>
    <records>805</records>
    <rows>
        <DocumentElement>
            <data>
                <CardCode>a</CardCode>
                <CardName>aasas as</CardName>
                <CardType>C</CardType>
                <Balance>0.000000</Balance>
            </data>
            <data>
                <CardCode>A0001</CardCode>
                <CardName>Manish Chourasia</CardName>
                <CardType>C</CardType>
                <Balance>100000.000000</Balance>
            </data>
            <data>
                <CardCode>A0002</CardCode>
                <CardName>Manish Chourasia</CardName>
                <CardType>C</CardType>
                <Balance>568368.000000</Balance>
            </data>
            <data>
                <CardCode>A0003</CardCode>
                <CardName>Vivek</CardName>
                <CardType>C</CardType>
                <Balance>0.000000</Balance>
            </data>
            <data>
                <CardCode>A00034</CardCode>
                <CardName>TUSHAR NATHWANI</CardName>
                <CardType>C</CardType>
                <Balance>0.000000</Balance>
            </data>
        </DocumentElement>
    </rows>
</Root>

我尝试了很多来调整xmlReader,但是没有用。我对xmlReader的行为完全感到困惑。

有人能帮助我吗?

1 个答案:

答案 0 :(得分:1)

您应该将xmlReader修复为以下内容:

xmlReader: {
     repeatitems: false,
     total: "Root>total",
     page: "Root>page",
     records: "Root>records",
     root: "Root>rows>DocumentElement",
     row: "data"
}