<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>joe-ferraro.com &#187; extjs</title>
	<atom:link href="http://joe-ferraro.com/tag/extjs/feed/" rel="self" type="application/rss+xml" />
	<link>http://joe-ferraro.com</link>
	<description>adless since 2008</description>
	<lastBuildDate>Wed, 25 Aug 2010 15:49:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>extjs &amp; visualforce (part 2), JSON this time</title>
		<link>http://joe-ferraro.com/2009/04/extjs-vf-json/</link>
		<comments>http://joe-ferraro.com/2009/04/extjs-vf-json/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 14:45:14 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[apex]]></category>
		<category><![CDATA[salesforce]]></category>
		<category><![CDATA[visualforce]]></category>
		<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://joe-ferraro.com/?p=65</guid>
		<description><![CDATA[Let me preface this post by stating that the following is merely a proof of concept and should not necessarily be implemented into a production org.  The pagination demonstrated below is not fit for large datasets and may result in unexpected behavior!  
Rich Waters&#8217; comment on my first post re: Ext JS &#038; [...]]]></description>
			<content:encoded><![CDATA[<p>Let me preface this post by stating that the following is merely a <em>proof of concept</em> and <u>should not</u> necessarily be implemented into a production org.  The pagination demonstrated below is not fit for large datasets and may result in unexpected behavior!  </p>
<p><a href="http://joe-ferraro.com/2009/04/extjs-visualforce/#comment-1164" target=new>Rich Waters&#8217; comment</a> on my <a href="http://joe-ferraro.com/2009/04/extjs-visualforce/" target=new>first post re: Ext JS &#038; visualforce</a> got me thinking about the possibilities of leveraging JSON in Ext JS components within Visualforce, so I implemented a paging grid, similar to <a href="http://extjs.com/deploy/dev/examples/grid/paging.html" target=new>this example provided by Ext JS</a>.  OK, enough of the formalities, I suppose people want to see what kind of development ensued:</p>
<p>First, the product, a JSON-based Ext JS paging grid:</p>
<div>
 <IFRAME src="http://crmmanager-developer-edition.na6.force.com/test/ExtJs_Json_Grid" height="400" width="650" frameborder="0" scrolling="no" ></IFRAME>
</div>
<p>Now, for the magic behind the grid, the JSON file (a Visualforce page called &#8220;Json_test&#8221;):</p>
<pre name="code" class="java">

&lt;apex:page contentType=&quot;text/html&quot; showHeader=&quot;false&quot; controller=&quot;Json_File&quot; &gt;
	&lt;apex:outputText value=&quot;{!json}&quot; /&gt;
&lt;/apex:page&gt;
</pre>
<p>The controller (spits out the JSON):</p>
<pre name="code" class="java">

public class Json_File {

	public string json {get;set;}

	public Json_File() {
        opportunity[] opps = new opportunity[]{};

	integer start = 0;
	integer pageSize = 10;

	if (ApexPages.currentPage().getParameters().get(&#039;start&#039;) != null &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; ApexPages.currentPage().getParameters().get(&#039;limit&#039;) != null) {
		start = integer.valueof(ApexPages.currentPage().getParameters().get(&#039;start&#039;));
		pageSize = integer.valueof(ApexPages.currentPage().getParameters().get(&#039;limit&#039;));
	}

        string jsonRecordsString = &#039;&#039;;

        integer i = 1;
        integer j = 0;

        for (Opportunity o : [Select id, name, stagename, closedate from opportunity order by name limit 1000]) {
			if (j &gt;= start) {
				if (i &lt;= pageSize) {
					jsonRecordsString += &#039;{&#039;;
					jsonRecordsString += &#039;&quot;id&quot;:&#039; + &#039;&quot;&#039;+o.id+&#039;&quot;,&#039;;
					jsonRecordsString += &#039;&quot;name&quot;:&#039; + &#039;&quot;&#039;+o.name+&#039;&quot;,&#039;;
					jsonRecordsString += &#039;&quot;stagename&quot;:&#039; + &#039;&quot;&#039;+o.stagename+&#039;&quot;,&#039;;
					jsonRecordsString += &#039;&quot;closedate&quot;:&#039; + &#039;&quot;&#039;+o.closedate+&#039;&quot;&#039;;
					jsonRecordsString += &#039;},&#039;;
					i++;
				}
			}
			opps.add(o);
			j++;
        }

		string jsonString = &#039;({&quot;total&quot;:&quot;&#039;+opps.size()+&#039;&quot;, &quot;results&quot;:[&#039; + jsonRecordsString + &#039;]})&#039;;
        jsonString = jsonString.replaceAll(&#039;,]&#039;,&#039;]&#039;);
        this.json = jsonString;
	}
}
</pre>
<div style="margin-top:50px;">
<p>Finally, the grid itself (from the Visualforce page embedded above in this post):</p>
<p>*It&#8217;s important to note that this Visualforce page does not have a controller; the JsonStore provides the reference needed (url) [see below] to access the future backend of the grid.
</p></div>
<pre name="code" class="javascript">

&lt;script type=&quot;text/javascript&quot;&gt;
	var opportunity_grid;

	Ext.onReady(
		function() {
			//prevents mixed content message in ie
			Ext.BLANK_IMAGE_URL = &#039;/s.gif&#039;;
			Ext.SSL_SECURE_URL = &#039;/s.gif&#039;;
			render_queue();
		}
	);

	function render_queue() {
		// create the data store
		var store = new Ext.data.JsonStore({
			totalProperty: &#039;total&#039;,	// total data, see json output
			root: &#039;results&#039;,	// see json output
			url: &#039;http://crmmanager-developer-edition.na6.force.com/test/Json_test&#039;,
	        fields: [
	           {name: &#039;id&#039;},
	   			&#039;name&#039;, &#039;stagename&#039;, &#039;closedate&#039;
       		]
   		});

		var pagingBar = new Ext.PagingToolbar({
	        pageSize: 10,
	        store: store,
	        displayInfo: true,
	        displayMsg: &#039;Displaying opportunities {0} - {1} of {2}&#039;,
	        emptyMsg: &quot;No opportunities to display&quot;
	    });

		var gridView = new Ext.grid.GridView({
				forceFit: true
		}); 

	    opportunity_grid = new Ext.grid.GridPanel({
	        store: store,
	        columns: [
	            {header: &quot;name&quot;, width: 150, dataIndex: &#039;name&#039;, sortable: true},
	            {header: &quot;stage&quot;, width: 150, dataIndex: &#039;stagename&#039;, sortable: true},
	            {header: &quot;close date&quot;, width: 150, dataIndex: &#039;closedate&#039;, sortable: true}
	        ],
	        width:580,
	        height:300,
	        loadMask: true,
	        bbar: pagingBar,
	        view: gridView,
	        layout: &#039;fit&#039;
	    });
		try {
			opportunity_grid.render(&#039;opportunity_grid&#039;);
		} catch(e){}	

		store.load({params:{start:0, limit:10}});
	}
&lt;/script&gt;
</pre>
<p>As you can see, the Json_File controller accepts two params (start, pageSize), which are sent from the store in store.load() to manage the index of the query and the number of records returned.  Unfortunately, Salesforce does not provide an &#8220;INDEX&#8221; keyword in SOQL, which would make this pagination much more &#8220;resource respectful&#8221; (each time page up/page down is called from the paging grid, we receive a full dataset from Salesforce which, as you might guess, can be dangerous for tables with more than a thousand records).</p>
<p>I looked into the possibility of leveraging <a href="http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_standardsetcontroller.htm">StandardSetController</a>, but given the out-of-box architecture of the paging grid, we&#8217;d still be calling our JSON controller each time the grid was &#8220;paged&#8221;, which effectively calls the entire dataset.</p>
<p>I&#8217;m open to ideas, so please weigh in.</p>
<p><span style="color:red;font-weight:bold;">EDIT: the source for the above example&#8230;</span><br />
<a href="http://joe-ferraro.com/blog-resources/ExtJs_Json_Grid.page">ExtJs_Json_Grid.page</a><br />
<a href="http://joe-ferraro.com/blog-resources/Json_Controller.cls">Json_Controller.cls</a><br />
<a href="http://joe-ferraro.com/blog-resources/Json_test.page">Json_test.page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joe-ferraro.com/2009/04/extjs-vf-json/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>extjs &amp; visualforce</title>
		<link>http://joe-ferraro.com/2009/04/extjs-visualforce/</link>
		<comments>http://joe-ferraro.com/2009/04/extjs-visualforce/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 15:20:59 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[salesforce]]></category>
		<category><![CDATA[visualforce]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[force.com sites]]></category>

		<guid isPermaLink="false">http://joe-ferraro.com/?p=64</guid>
		<description><![CDATA[
I&#8217;m interested to hear how people are utilizing extjs in their visualforce pages.  I&#8217;ve found it very helpful to use Apex to generate the store on the server side, then pass it along to the Visualforce page via a hidden input to be handled on the client side (rather than use the apex:repeat tags).
Note: [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;m interested to hear how people are utilizing extjs in their visualforce pages.  I&#8217;ve found it very helpful to use Apex to generate the store on the server side, then pass it along to the Visualforce page via a hidden input to be handled on the client side (rather than use the apex:repeat tags).</p>
<p>Note: once again, the grid below is a live Visualforce page from my developer Force.com site embedded into this post
</p>
<div>
 <IFRAME src="http://crmmanager-developer-edition.na6.force.com/test/ExtJs_Grid" height="400" width="650" frameborder="0" scrolling="no" ></IFRAME>
</div>
<pre name="code" class="java">

public class Grid_Controller {
	public string store {get;set;}
	public list&lt;QueueItem&gt; queueitems {get;set;}
	string userId = UserInfo.getUserId();

	public Grid_Controller() {
		queueitems = new queueitem[]{};
		for (Custom_Process_Instance__c cpi : [Select Owner.Name, Opportunity__r.Name, Opportunity__r.Id, (Select Id From Custom_Process_Instance_Step__r where Status__c != &#039;Completed&#039; AND Status__c = &#039;Pending&#039; limit 1), Percent_Complete__c, Process_Age__c from Custom_Process_Instance__c where Status__c = &#039;Pending&#039; AND Opportunity__c != null and IsDeleted = false order by CreatedDate asc]) {
            		QueueItem qi = new QueueItem(cpi);
            		queueitems.add(qi);
		}        

		string myDataString = &#039;var myData = [ &#039;;
		for(queueitem q : this.queueitems) {
			string showIcon = &#039;&#039;;
			if (q.ProcessInstance.Custom_Process_Instance_Step__r.size() == 1)
        			showIcon = &#039;yes&#039;;

			string oppId = q.ProcessInstance.Opportunity__c;
			string oppName = q.ProcessInstance.Opportunity__r.Name;
			string launchedby = q.ProcessInstance.Owner.Name;
			double percent = q.ProcessInstance.Percent_Complete__c;
			double ageInMinutes = q.ProcessInstance.Process_Age__c;

			if (q.ProcessInstance.Opportunity__r.Name != null)
				oppName = string.escapeSingleQuotes(q.ProcessInstance.Opportunity__r.Name);
			if (q.ProcessInstance.Owner.Name != null)
				launchedBy = string.escapeSingleQuotes(q.ProcessInstance.Owner.Name);

			myDataString += &#039;[\&#039;&#039;+showIcon+&#039;\&#039;,\&#039;&#039;+oppName+&#039;\&#039;, \&#039;&#039;+oppId+&#039;\&#039;,\&#039;&#039;+launchedBy+&#039;\&#039;,\&#039;&#039;+percent+&#039;\&#039;,\&#039;&#039;+ageInMinutes+&#039;\&#039;],&#039;;
		}

		myDataString += &#039;];&#039;;
		myDataString = myDataString.replace(&#039;,];&#039;, &#039;];&#039;);
		this.store = myDataString;
	}

	public class QueueItem {
		public Custom_Process_Instance__c ProcessInstance {get;set;}
		public QueueItem(Custom_Process_Instance__c cpi) {
			this.ProcessInstance = cpi;
		}
	}
}
</pre>
<pre name="code" class="java">

&lt;script type=&quot;text/javascript&quot;&gt;
	var myDataString = document.getElementById(&#039;{!$Component.myForm.dataStore}&#039;).value;
&lt;/script&gt;
</pre>
<pre name="code" class="java">

&lt;apex:form id=&quot;myForm&quot;&gt;
	&lt;apex:inputHidden value=&quot;{!store}&quot; id=&quot;dataStore&quot;/&gt;
&lt;/apex:form&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://joe-ferraro.com/2009/04/extjs-visualforce/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
