dojo - Filling Dojox.grid.DataGrid with JSON Data -


i have json data in format :

var jsondata = [{date:'august 19, 2004',open:100.01,high:104.06},{date:'august 19, 2004',open:100.01,high:104.06},{date:'august 19, 2004',open:100.01,high:104.06}]; 

how can print data inside dojox.grid.datagrid

<body class=" claro ">         <span dojotype="dojo.data.itemfilereadstore" jsid="store1" url="data.json">         </span>         <table dojotype="dojox.grid.datagrid" store="store1"         style="width: 100%; height: 100%;">             <thead>                 <tr>                     <th width="150px" >                         title of movie                     </th>                     <th width="150px">                         year                     </th>                     <th width="150px" >                         producer                     </th>                 </tr>              </thead>         </table>      </body> 

remeber itemfilereadstore (all types of stores actually) need data in specific format. telling me have jsondata variable:

var jsondata = [{date:'august 19, 2004',open:100.01,high:104.06},{date:'august 19, 2004',open:100.01,high:104.06},{date:'august 19, 2004',open:100.01,high:104.06}]; 

this not format itemfilereadstore wants. itemfilereadstore wants object @ least 2 properties: identifier , items. change data to:

var jsondata = {identifier: "id",                  items: [                   {id: 1, date:'august 19, 2004',open:100.01,high:104.06},                   {id: 2, date:'august 19, 2004',open:100.01,high:104.06},                   {id: 3, date:'august 19, 2004',open:100.01,high:104.06}                 ]}; 

as can see, it's object required properties. identifier property tells store use property named "id" uniquely distinguish items. objects didn't have unique property, added id property on items. have other property can use.

next, since have data in variable, why telling itemfilereadstore data url called data.json? instead, do:

<span dojotype="dojo.data.itemfilereadstore" jsid="store1" data="jsondata"></span> 

lastly, grid itself. table headers need correspond properties on items in store. have, example date, open , high, use field attribute on each th:

<table dojotype="dojox.grid.datagrid" store="store1"     style="width: 100%; height: 500px;">     <thead>         <tr>             <th width="150px" field="date">title of movie</th>             <th width="150px" field="open">year</th>             <th width="150px" field="high">producer</th>         </tr>     </thead> </table> 

i added "height: 500px" table, may not necessary you.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -