2013-10-29 85 views
0

我想用新的Dgrid替換dojox.grid.DataGrid,但我遇到了問題。我使用道場1.9.1這裏是我的代碼摘錄:Dojo Dgrid的故障

HTML:

<script type="text/javascript"><!-- 
require({ 
    baseUrl: "/res/js/", 
    packages: [ 
     { name: "dojo", location: "dojo/dojo" }, 
     { name: "dijit", location: "dojo/dijit" }, 
     { name: "dojox", location: "dojo/dojox" }, 
     { name: "put-selector", location: "put-selector" }, 
     { name: "xstyle", location: "xstyle" }, 
     { name: "dgrid", location: "dgrid" }, 
     { name: "allwins", location: "allwins" } 
    ] 
},[ 
    "allwins/Admin", 
    "dojo/parser", 
    "dojo/domReady!" 
],function(admin, Parser){ 
    admin.initUi(/*...*/); 
}); 
</script> 
<!-- ... --> 
<div data-dojo-id="invoicesTab2" 
    data-dojo-type="dijit.layout.BorderContainer" 
    data-dojo-props="region: 'center', 
         title: 'Faktury 2'"> 
    <div id=invoicesGridTab2"></div> 
</div> 

的JavaScript:

request(invoicesDataUrl, { 
    handleAs: "json" 
}).then(function (response) { 
    var store = new Memory({ data: response }); 
    var grid = new OnDemandGrid({ 
     region: "center", 
     store: store, 
     columns: { 
      invoice_id: { label: "FID" }, 
      user_id: { label: "UID" }, 
      invoice_no: { label: "Číslo" }, 
      user_fullname: { label: "Plátce" }, 
      created_formatted: { label: "Vystavena" }, 
      payment_date_formatted: { label: "Splatnost" }, 
      payment_total: { label: "Částka" } 
     } 
    }, "invoicesGridTab2"); 
    grid.startup(); 
}); 

,我可以添加一些更多的東西:

  • 列表項目
  • 我在JavaScript控制檯沒有錯誤
  • 數據源已與使用舊dojox.grid.DataGrid
  • 測試,似乎主要問題是與渲染

感謝任何幫助或建議!

+0

「更多的東西」中的「列表項」是一個錯誤:( –

回答

1

您需要在響應數據對象匹配的列以指定字段屬性,例如:

request(invoicesDataUrl, { 
    handleAs: "json" 
}).then(function (response) { 
    var store = new Memory({ data: response }); 
    var grid = new OnDemandGrid({ 
     region: "center", 
     store: store, 
     columns: { 
      invoice_id: { label: "FID", field: "invoice_id" }, 
      user_id: { label: "UID", field: "user_id" }, 
      invoice_no: { label: "Číslo", field: "invoice_no" }, 
      user_fullname: { label: "Plátce", field: "user_fullname" }, 
      created_formatted: { label: "Vystavena", field: "created_formatted" }, 
      payment_date_formatted: { label: "Splatnost", field: "payment_date_formatted" }, 
      payment_total: { label: "Částka", field: "payment_total" } 
     } 
    }, "invoicesGridTab2"); 
    grid.startup(); 
}); 

我不知道,如果這些字段名稱是正確的,但我相信你會的。 :)

+0

真的非常感謝 - 我首先有字段聲明像對象的數組與字段和標籤屬性聲明(喜歡你現在建議)),但這樣做不工作(但我在dgrid主頁上看到)...您指出的這個變體很好用......再次感謝。通過。 –

+1

當你指定'columns'作爲一個對象時,默認情況下這些鍵被重用爲'field'屬性的值,所以我不確定你的原始代碼如何工作。 –