2013-10-29 66 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'属性的值,所以我不确定你的原始代码如何工作。 –