<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: Grid with local array of custom objects</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>pepbr on Grid with local array of custom objects</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects#p26835</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects#p26835</guid>
        	        	<description><![CDATA[<p>Hi Pradeep.</p>
</p>
<p>I forgot to mention I am trying to find a way to do this without adding row by row. I found a way that is working for me so far and this involves transforming by object back to Json. I wonder if there&#39;s a way to map the columns to some data.</p>
<p>Here is what I did:</p>
</p>
<p>I am using this library to convert my object back to Json:</p>
<p><a href="https://github.com/douglascrockford/JSON-js/blob/master/json2.js" rel="nofollow" target="_blank">https://github.com/douglascrockford/JSON-js/blob/master/json2.js</a></p>
</p>
<p>Then I had to add a prototype to my objecy like this (right now I am using just a few fields and not diggin into other objects in my object):</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1668' value='Select Code' data-codeid='sfcode1668' /></p>
<div class='sfcode' id='sfcode1668'>Vehicle.prototype.toJSON = function (key) {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; var returnObj = new Object();<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; returnObj.devid = this.devid;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; returnObj.name = this.name;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; returnObj.speed = this.speed;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; returnObj.status = this.status;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; returnObj.distanceToAddress = parseFloat(this.distanceToAddress);&#160;&#160; //Google Maps stuff<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; returnObj.distanceAsString = this.distanceAsString; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; //Google Maps stuff<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; return returnObj;<br />&#160;&#160; &#160;&#160;&#160; }</div>
<p>By doing this I am telling the json2 how to build json out of my object.</p>
</p>
<p>Then, to generate the json:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit6176' value='Select Code' data-codeid='sfcode6176' /></p>
<div class='sfcode' id='sfcode6176'>vehiclesJson = &#34;{\&#34;vehicles\&#34;:&#34; + JSON.stringify(this.vehicles) + &#34;}&#34;;</div>
<p>And my grid setup become like this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3318' value='Select Code' data-codeid='sfcode3318' /></p>
<div class='sfcode' id='sfcode3318'>.jqGrid({ <br />&#160;&#160; &#160;&#160;&#160; &#160;datastr: vehiclesJson, <br />&#160;&#160; &#160;&#160;&#160; &#160;datatype: &#34;jsonstring&#34;, <br />&#160;&#160; &#160;&#160;&#160; &#160;jsonReader : {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; root: &#34;vehicles&#34;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; page: function(obj){return 1;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; total: function(obj){return 1;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; records: function(mvs){return mvs.vehicles.length},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; repeatitems: false,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; cell: &#34;cell&#34;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; id: &#34;devid&#34;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; },</div>
<p>This is how I managed it to work out fine. But I wonder if there&#39;s a way to accomplish the same result without converting the object back to json.</p>
</p>
<p>Thanks,</p>
<p>Paulo</p>
]]></description>
        	        	<pubDate>Fri, 22 Jun 2012 15:27:46 +0300</pubDate>
        </item>
        <item>
        	<title>Pradeep Reddy Billa on Grid with local array of custom objects</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects#p26834</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects#p26834</guid>
        	        	<description><![CDATA[<p>Try adding data as row by row from a Json object..</p>
</p>
<p>Somethign like this :</p>
</p>
<p>&#160;for (var i = 0; i &#60;= mydata.length; i++)</p>
<p>&#160;&#160;&#160;&#160;&#160; $("#" + gridName).jqGrid(&#39;addRowData&#39;, i + 1, mydata[i]);<span id="_marker">&#160;</span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><br />
</span></span></p>
<p>where mydata is a json obect contains the data.</p>
</p>
<p>Cheers,</p>
<p>Pradeep Reddy Billa</p></p>
]]></description>
        	        	<pubDate>Fri, 22 Jun 2012 08:58:38 +0300</pubDate>
        </item>
        <item>
        	<title>pepbr on Grid with local array of custom objects</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects#p26821</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/grid-with-local-array-of-custom-objects#p26821</guid>
        	        	<description><![CDATA[<p>Hello.</p>
<p>First of all I would like to express my deep appreciation to the grid plugin. I am a regular user.</p>
<p>But this time I am facing a new and challenging situation: my grid is using only LOCAL DATA.</p>
</p>
<p>I spent hours searching the net for a solution but I simply can&#39;t put it together, then I decided to post my question.</p>
</p>
<p>I am reading a database and creating a custom javascript object out of its rows. This array is being used by some other codes to display information on a map (using Google Maps api).</p>
</p>
<p>Someone requested the data should also be displayed on a table and then here I am, trying to populate my grid with the current loaded array of objects.</p>
</p>
<p>The grid columns are defined by this:</p>
<p>colModel:[ <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;id&#39;,index:&#39;id&#39;, width:50, editable:false}, <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;vehicle&#39;,index:&#39;vehicle&#39;, width:110, editable:false}, <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;select&#39;,index:&#39;select&#39;, width:30, editable:false},&#160; //will be used to select rows</p>
<p>]</p>
</p>
<p>The array of objects is accessed by:</p>
<p>mvs.getVehicles();</p>
</p>
<p>And the values for each column relies in:</p>
<p>var v = mvs.getVehicles[x];</p>
<p>column ID is v.devid</p>
<p>column Vehicle is v.name</p>
</p>
<p>Please shed some light on me.</p>
</p>
<p>Thanks a million,</p>
<p>Paulo Pedroso</p>
]]></description>
        	        	<pubDate>Wed, 20 Jun 2012 00:33:57 +0300</pubDate>
        </item>
</channel>
</rss>