2009-05-01 9 views
1

In den folgenden Beispieldaten wird nur im Raster angezeigt, wenn die JSON-Daten eine Namensspalte enthält -> das erste Raster zeigt Daten, das zweite nicht.Warum benötigt Dojo-Grid eine Namensspalte in der JSON-Datenquelle

Warum ist das der Fall?

index.html: dojo grid

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dijit/themes/tundra/tundra.css" /> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/resources/dojo.css" /> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojox/grid/_grid/tundraGrid.css"> 
    <script type="text/javascript" 
      src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js" 
      djConfig="parseOnLoad: true, isDebug: true"> 
    </script> 

    <script type="text/javascript"> 
     dojo.require("dojo.parser"); 
     dojo.require("dojox.grid.Grid"); 
     dojo.require("dojo.data.ItemFileReadStore"); 
    </script> 

    </head> 
    <body class="tundra"> 
    <span dojoType="dojo.data.ItemFileReadStore" 
      jsId="withNameStore" 
      url="WithNameColumn.json" 
      clearOnClose="true"> 
    </span> 
    <table id="withNameGrid" 
      dojoType="dojox.grid.Grid" 
      store="withNameStore" 
      clientSort="true" 
      style="width: 20em; height: 20em;"> 
     <thead> 
      <tr> 
       <th field="ID" >ID</th> 
       <th field="test">Test</th> 
      </tr> 
     </thead> 
    </table> 
    <span dojoType="dojo.data.ItemFileReadStore" 
      jsId="withoutNameStore" 
      url="WithoutNameColumn.json" 
      clearOnClose="true"> 
    </span> 
    <table id="withoutNameGrid" 
      dojoType="dojox.grid.Grid" 
      store="withoutNameStore" 
      clientSort="true" 
      style="width: 20em; height: 20em;"> 
     <thead> 
      <tr> 
       <th field="ID" >ID</th> 
       <th field="test">Test</th> 
      </tr> 
     </thead> 
    </table> 
    </body> 
</html> 

WithNameColumn.json:

{ 
    "identifier":"ID", 
    "label":"test", 
    "items": 
    [{"ID":2,"name":"name1","test":"dog"}, 
    {"ID":3,"name":"name2","test":"cat"}, 
    {"ID":4,"name":"name3","test":"mouse"}] 
} 

WithoutNameColumn.json:

{ 
    "identifier":"ID", 
    "label":"test", 
    "items": 
    [{"ID":2,"test":"dog"}, 
    {"ID":3,"test":"cat"}, 
    {"ID":4,"test":"mouse"}] 
} 

Antwort

2

Fügen Sie einfach ein Query-Attribut zu Ihrem Element hinzu. Wie folgt aus:

< Tabelle query = "{ID: '*'}" ... >

Dies liegt daran, dass eine Abfrage durchführen, wenn Daten aus dem Datenspeicher

+0

ich anfordernden warum dies löst die Problem, aber es tut. Danke. – simon

0

Spalt Name ist nicht erforderlich Sie jedoch eine Karte zwischen Objekt im Datenspeicher und Spaltennamen in den Raster tun müssen. Dies geschieht, wenn Sie das Raster 'Layout' definieren. Die Eigenschaft 'Feld' im 'Layout' ist der Name der Spalte im Datenspeicher (der Name der Eigenschaft, um genau zu sein) und die 'Name' Eigenschaft in der "Layout" ist der Spaltenname im Raster.

gridLayout = [{ 
     defaultCell: { width: 8, editable: true, type: dojox.grid.cells._Widget, styles: 'text-align: right;' }, 
     rows: [ 
      { name: 'Id', field: 'id', editable: false /* Can't edit ID's of dojo.data items */ }, 
      { name: 'Date', field: 'col8', width: 10, 
       type: dojox.grid.cells.DateTextBox, 
       formatter: formatDate, 
       constraint: {formatLength: 'long', selector: "date"}}, 
      { name: 'Priority', styles: 'text-align: center;', field: 'col1', 
       type: dojox.grid.cells.ComboBox, 
       options: ["normal", "note", "important"], width: 10}, 
      { name: 'Mark', field: 'col2', width: 3, styles: 'text-align: center;', 
       type: dojox.grid.cells.CheckBox}, 
      statusCell, 
      { name: 'Message', field: 'col4', styles: '', width: 10, 
       type: dojox.grid.cells.Editor, editorToolbar: true }, 
      { name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, 
       widgetClass: dijit.form.CurrencyTextBox }, 
      { name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, 
       widgetClass: dijit.form.HorizontalSlider, width: 10} 
     ] 
    }]; 
Verwandte Themen