2012-02-15 122 views
1

我這樣的XML:test.xmljqGrid的數據xml屬性

<?xml version="1.0" encoding="utf-8"?> 
<root> 
    <R c="0" n="a"/> 
    <R c="1" n="b"/> 
    <R c="2" n="c"/> 
</root> 

如何綁定到的jqGrid?我試過這樣的:

jQuery("#ourunittb").jqGrid({ 
    url: 'test.xml', 
    datatype: "xml", 
    height: 1000, 
    colNames: ['mycode, 'myname'], 
    colModel: [ 
     { width: 60, xmlmap: "root>R>c" }, 
     { width: 90, xmlmap: "root>R>n" } 
    ], 
    xmlReader: { 
     root: "root", 
     row: "R", 
     repeatitems: false 
    }, 
    rowNum: 1000, 
    autowidth: true    
}); 

但我無法獲取數據。請幫幫我。非常感謝

回答

0

jqGrid的當前版本支持的xmlReaderxmlmap內部功能(見我的原始特徵的要求here)。所以,你可以修改你的JavaScript代碼如下:

$("#ourunittb").jqGrid({ 
    url: 'test.xml', 
    datatype: "xml", 
    height: 'auto', 
    colModel: [ 
     { name: 'mycode', width: 80, sorttype: 'int', 
      xmlmap: function (obj) { 
       return $(obj).attr('c'); 
      }}, 
     { name: 'myname', width: 90, xmlmap: function (obj) { 
       return $(obj).attr('n'); 
      }} 
    ], 
    xmlReader: { 
     root: "root", 
     row: "R", 
     repeatitems: false 
    }, 
    loadonce: true, 
    rowNum: 1000 
}); 

的結果,你可以在the demo看到:

enter image description here

我加入loadonce: true選項和sorttype屬性,以支持本地排序在加載格。以同樣的方式,您可以使用本地分頁和本地數據過濾(使用toolbar searchingadvanced searching

+0

非常感謝。我真的很感激。如果沒有你的幫助,我真的不知道我會做什麼。 – jacky 2012-02-16 03:01:27

+0

@jacky:不客氣!我很高興我能幫助你。 – Oleg 2012-02-16 06:09:58