<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'I could not get Grid to work using Example in the book' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/58/topics/338</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>I could not get Grid to work using Example in the book posted by Jason Lehman @ Fri, 28 Mar 2008 17:58:34 -0000</title>
      <description>&lt;p&gt;My bad.  I was using the 1.0 release and should have been using the 1.1 release.  I have upgraded and now I am good with the example in the book.&lt;/p&gt;</description>
      <pubDate>Fri, 28 Mar 2008 17:58:34 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:58:338:2504</guid>
      <author>Jason Lehman</author>
      <link>http://forums.pragprog.com/forums/58/topics/338</link>
    </item>
    <item>
      <title>I could not get Grid to work using Example in the book posted by Jason Lehman @ Thu, 27 Mar 2008 17:03:25 -0000</title>
      <description>&lt;p&gt;I didn&amp;#8217;t know if I should add it to the Errata until I figured out if it was me or not.  I am posting the code.  Please let me know if I was just missing something from the example.&lt;/p&gt;


	&lt;p&gt;Here were the things I had to do to get it to work:&lt;/p&gt;


	&lt;p&gt;1. programmatically get the &lt;span class="caps"&gt;JSON&lt;/span&gt; store because I couldn&amp;#8217;t get the inline code version to ever do the &lt;span class="caps"&gt;XHR&lt;/span&gt;&lt;/p&gt;


&lt;code&gt;      
var jsonStore = new dojo.data.ItemFileReadStore ({ url: "users.json"});
jsonStore.fetch();
&lt;/code&gt;

	&lt;p&gt;2. Add a view and layout:&lt;/p&gt;


&lt;code&gt;
            var view1 = {
                cells: [[
                    {name: 'First Name', field: "first_name"}, 
                    {name: 'Last Name', width: "25em", field: "last_name"}
                  ],
                  [
                    {name: 'Username', colSpan:"2", field: "username"}
                  ]
                ]
            };
            var layout = [ view1 ];
&lt;/code&gt;

	&lt;p&gt;3. Add a model and reference it in the table definition:&lt;/p&gt;


&lt;code&gt;
        &amp;lt;div dojoType="dojox.grid.data.DojoData" jsId="model" rowsPerPage="20" store="jsonStore"  query="{ id:'*' }" &amp;gt;
        &amp;lt;table id="grid" dojoType="dojox.Grid" model="model"&amp;gt;
        &amp;lt;/table&amp;gt;
&lt;/code&gt;

	&lt;p&gt;And here is the complete code that worked for me:&lt;/p&gt;


&lt;code&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"&amp;gt;
&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;
            Grid
        &amp;lt;/title&amp;gt;
        &amp;lt;style type="text/css"&amp;gt; 
        @import "/dojoroot/dijit/themes/tundra/tundra.css"; 
        @import "/dojoroot/dojo/resources/dojo.css";
        @import "/dojoroot/dojox/grid/_grid/tundraGrid.css";
        &amp;lt;/style&amp;gt;
        &amp;lt;style&amp;gt; 
        #grid { 
        border: 1px solid #333; 
        width: 550px; 
        margin: 10px; 
        height: 200px; 
        font-size: 0.9em; 
        font-family: Geneva, Arial, Helvetica, sans-serif; 
        } 
        &amp;lt;/style&amp;gt;        
    &amp;lt;script type="text/javascript" src="/dojoroot/dojo/dojo.js" djconfig="parseOnLoad: true"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
      dojo.require("dojo.parser");
      dojo.require("dojo.data.ItemFileReadStore");
      dojo.require("dojox.grid.Grid");
      dojo.require("dojox.grid._data.model");
      var jsonStore = new dojo.data.ItemFileReadStore ({ url: "users.json"});
      jsonStore.fetch();
            // a grid view is a group of columns
            var view1 = {
                cells: [[
                    {name: 'First Name', field: "first_name"}, 
                    {name: 'Last Name', width: "25em", field: "last_name"}
                  ],
                  [
                    {name: 'Username', colSpan:"2", field: "username"}
                  ]
                ]
            };
            var layout = [ view1 ];
    &amp;lt;/script&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body class="tundra"&amp;gt;
        &amp;lt;div dojoType="dojox.grid.data.DojoData" jsId="model" rowsPerPage="20" store="jsonStore"  query="{ id:'*' }" &amp;gt;
        &amp;lt;table id="grid" dojoType="dojox.Grid" model="model"&amp;gt;
        &amp;lt;/table&amp;gt; 

    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;</description>
      <pubDate>Thu, 27 Mar 2008 17:03:25 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:58:338:2496</guid>
      <author>Jason Lehman</author>
      <link>http://forums.pragprog.com/forums/58/topics/338</link>
    </item>
  </channel>
</rss>
