<?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>Harish Sivaramakrishnan &#187; tutorials</title>
	<atom:link href="http://blog.flexgeek.in/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexgeek.in</link>
	<description>Platform Evangelist @ Adobe</description>
	<lastBuildDate>Thu, 15 Jul 2010 06:30:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Video Tutorial: Building a List with realtime data using Flash Catalyst, Photoshop and Flash Builder 4</title>
		<link>http://blog.flexgeek.in/2009/06/video-tutorial-building-a-list-with-realtime-data-using-flash-catalyst-photoshop-and-flash-builder-4/</link>
		<comments>http://blog.flexgeek.in/2009/06/video-tutorial-building-a-list-with-realtime-data-using-flash-catalyst-photoshop-and-flash-builder-4/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 14:03:36 +0000</pubDate>
		<dc:creator>Harish Sivaramakrishnan</dc:creator>
				<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[flash catalyst]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://blog.flexgeek.in/?p=361</guid>
		<description><![CDATA[Check out the 4 part video tutorial on building a DataList which uses realtime data using an Adobe Photoshop PSD, Flash Catalyst &#38; Flash Builder 4 in a single work flow. Check out the tutorial PART I &#124; PART II &#124; PART III &#124; PART IV This series also marks the launch of my video [...]]]></description>
			<content:encoded><![CDATA[<p>Check out the 4 part video tutorial on building a DataList which uses realtime data using an <strong>Adobe Photoshop PSD, Flash Catalyst &amp; Flash Builder 4 </strong>in a single work flow.</p>
<p><strong>Check out the tutorial</strong></p>
<h3><span style="color: #000000;"><a href="http://broadcast.flexgeek.in/?p=14" target="_self">PART I</a> | <a href="http://broadcast.flexgeek.in/?p=19" target="_self">PART II</a> | <a href="http://broadcast.flexgeek.in/?p=22" target="_self">PART III </a>| <a href="http://broadcast.flexgeek.in/?p=24" target="_self">PART IV</a></span></h3>
<p>This series also marks the launch of my video blog &#8211; <a href="http://broadcast.flexgeek.in" target="_blank"><strong>The Flexgeek Show</strong></a>. All my video tutorials will be henceforth posted in <strong>The Flexgeek Show</strong>. The blog will also feature under the hood sessions on various aspects of the Adobe Flash Platform tools by the flex engineering team, videos of Adobe events, customer interviews and many more fun stuff. Please do add <a href="http://broadcast.flexgeek.in" target="_blank"><strong>http://broadcast.flexgeek.in</strong></a> to your bookmarks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexgeek.in/2009/06/video-tutorial-building-a-list-with-realtime-data-using-flash-catalyst-photoshop-and-flash-builder-4/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tips &amp; Tricks : AdvancedDataGrid &#8211; grouping &amp; summary rows</title>
		<link>http://blog.flexgeek.in/2007/06/tips-tricks-advanceddatagrid-grouping-summary-rows/</link>
		<comments>http://blog.flexgeek.in/2007/06/tips-tricks-advanceddatagrid-grouping-summary-rows/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 08:03:29 +0000</pubDate>
		<dc:creator>vodka</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[tips & tricks]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://flexgeek.wordpress.com/2007/06/14/tips-tricks-advanceddatagrid-grouping-summary-rows/</guid>
		<description><![CDATA[This is the first among the series of articles that I intend to write about the new AdvancedDataGrid control of Flex 3.0 (moxie). You would require Flex 3 beta 1 to compile and run this example. If you dont have moxie yet, download it here Displaying grouped (hierarchical) data &#38; summary rows in AdvancedDataGrid One [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first among the series of articles that I intend to write about the new AdvancedDataGrid control of Flex 3.0 (<strong>moxie</strong>). You would require Flex 3 beta 1 to compile and run this example. If you dont have moxie yet, download it <strong><a href="http://labs.adobe.com/technologies/flex/flexbuilder3/">here</a><br />
</strong><br />
<strong>Displaying  grouped (hierarchical) data &amp; summary rows in AdvancedDataGrid</strong></p>
<p>One of the key features of the new AdvancedDataGrid (will be referred to as <strong>ADG</strong> from hereafter) is its inbuilt capablility to display hierarchical data. This is made possible through the new set of collections classes that have been added. The following example helps you learn two things:</p>
<ul>
<li>How to create a grouped data from the flat data that is supplied to ADG</li>
<li>Create summary rows based on the data.</li>
</ul>
<p><strong>Lets now look at the example <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
<p>The example in this article has an ADG which display the quarterly revenue details of companies and the number of licences sold by each one of them stored as an XMLList. This XMLList is supplied as the dataProvider for the ADG. (This is all similar to what you would do in the DataGrid).</p>
<p><a title="dgshot1.jpg" href="http://flexgeek.files.wordpress.com/2007/06/dgshot1.jpg"><br />
</a></p>
<p>Now, Lets try and group this data based on the field <strong>quarter</strong>. Lets look at the code that will let us do that</p>
<blockquote><p>//Make a grouping collection<br />
var mygroup:GroupingCollection=new GroupingCollection();<br />
//Set the source to the array collection (this case dataProvider)<br />
mygroup.source = colgrouped_adg.dataProvider;<br />
//Create a new grouping<br />
var group:Grouping = new Grouping();<br />
//Group on Quarter<br />
var gf:GroupingField = new GroupingField(&#8220;Quarter&#8221;);<br />
//Set the fields to the grouping<br />
group.fields = [gf];<br />
//Finally, Set the group to the grouping property of groupedCollection<br />
mygroup.grouping = group;<br />
//Refresh the group<br />
mygroup.refresh();<br />
//Set the dataProvider to the grouping collection<br />
colgrouped_adg.dataProvider = mygroup<br />
//Call validateNow() to redraw the dg.<br />
colgrouped_adg.validateNow()</p></blockquote>
<p><strong>The steps are as follows:</strong></p>
<ul>
<li>create a grouping collection</li>
<li>set the source to a flat collection (this case the ADG DataProvider)</li>
<li>create an instance of grouping</li>
<li>create a grouping field and pass the field that you want the data to be grouped on</li>
<li> set the fields property of the grouping to the groupField</li>
<li>set the grouping property of the grouping collection to grouping instance</li>
<li>refresh the grouping collection</li>
<li>set the dataProvider of ADG to the grouping collection</li>
<li>call validateNow() on ADG to update the display</li>
</ul>
<p><a title="dgshot3.jpg" href="http://flexgeek.files.wordpress.com/2007/06/dgshot3.jpg"><br />
</a></p>
<p>Now, Lets write some code to calculate the summary of the total number of licences sold by *ALL* companies. Here we go!</p>
<blockquote><p>var sr:SummaryRow = new SummaryRow();<br />
//Set the summaryObjectFunction<br />
//This function tells ADG to add a summary row in addition to the existing data<br />
sr.summaryObjectFunction = objFunc;<br />
//Set the summary field. The field on which the summary will be calculated.<br />
var sf:SummaryField = new SummaryField(&#8220;Licenses&#8221;);<br />
//Summary Function &#8211; the function that calculates the summary row display<br />
sf.summaryFunction = func;<br />
//set the summary rows fields property to summaryField<br />
sr.fields = [sf];<br />
//Place the summary row (Last means data First, summary Last!)<br />
sr.summaryPlacement = &#8220;last&#8221;;<br />
//Group on Quarter<br />
var gf:GroupingField = new GroupingField(&#8220;Quarter&#8221;);<br />
//set the summary row(s) to groupingField<br />
gf.summaries=[sr]</p></blockquote>
<p>Thats fairly straight forward. Here are the steps you need to follow to get a summary row in your ADG.</p>
<ul>
<li>Create a summary row instance</li>
<li>Set the summaryObjectFunction to include a summary in your ADG data</li>
<li>Create a summary field, the field on to which the summary calculation formula needs to be applied.</li>
<li>Write a summary function which contains the logic to calculate the summary</li>
<li>set the summaryField to the fields propety of summary row</li>
<li>Define summaryPlacement &#8220;First / Last&#8221; First will put summary before data, last will add it after the data</li>
<li>Finally set the summary rows to the groupingField.</li>
</ul>
<p>The SummaryObjectFunction looks like this: (This method returns a SummaryObject)</p>
<blockquote><p>private function objFunc():SummaryObject<br />
{<br />
var obj:SummaryObject = new SummaryObject();<br />
obj.summary = true;<br />
return obj;<br />
}</p></blockquote>
<p>Finally, the summary function. summaryFunction accepts 3 parameters (its a callback, you may never have to pass params to it, but be sure that you write the signature correctly) an iterator,a field and an operation. (operations include build-in methods like ADD).</p>
<blockquote><p>private function func(itr:IViewCursor,field:String, str:String=null):Object<br />
{<br />
var sum:Number=0<br />
while(!itr.afterLast)<br />
{<br />
//trace(itr.current)<br />
var value:Number = Number(itr.current.Licenses);<br />
if(!isNaN(value))<br />
{<br />
sum+= value<br />
}<br />
itr.moveNext()<br />
}<br />
return sum<br />
}</p></blockquote>
<p>Thats it! We are done and what we get will look like this <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a title="dgshot4.jpg" href="http://flexgeek.files.wordpress.com/2007/06/dgshot4.jpg"><br />
</a></p>
<p>I have included the sample application as well as full source code for this example. Do take a look at it. I hope this one was useful for all those who are exploring the new ADG. Do look out for more tutorials on this topic.</p>
<p><strong> <a href="https://share.acrobat.com/adc/document.do?docid=0183aedc-7ae2-43a2-b438-d2a0a174076b" target="_blank">Download Source</a></strong></p>
<p><strong>Do check out my <a href="http://blog.flexgeek.in/?p=26" target="_blank">Simple Gantt chart</a> built on AdvancedDataGrid </strong></p>
<p><a title="dgshot4.jpg" href="http://flexgeek.files.wordpress.com/2007/06/dgshot4.jpg"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexgeek.in/2007/06/tips-tricks-advanceddatagrid-grouping-summary-rows/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Tutorial: Using same itemRenderer for multiple columns</title>
		<link>http://blog.flexgeek.in/2007/05/tutorial-using-same-itemrenderer-for-multiple-columns/</link>
		<comments>http://blog.flexgeek.in/2007/05/tutorial-using-same-itemrenderer-for-multiple-columns/#comments</comments>
		<pubDate>Wed, 30 May 2007 07:51:57 +0000</pubDate>
		<dc:creator>vodka</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://flexgeek.wordpress.com/2007/05/30/tutorial-using-same-itemrenderer-for-multiple-columns/</guid>
		<description><![CDATA[Sample this case: You have 7 columns in your datagrid, each of which need an itemRenderer to display some conditional formatting by changing the background color based on the data belonging to that particular column. Ex &#8211; a value range of 1 &#8211; 10 will have colors varying from pale pink to red in column [...]]]></description>
			<content:encoded><![CDATA[<p>Sample this case: You have 7 columns in your datagrid, each of which need an itemRenderer to display some conditional formatting by changing the background color based on the data belonging to that particular column. Ex &#8211; a value range of 1 &#8211; 10 will have colors varying from pale pink to red in column 1, but te same value range will display pale green to bright green in column 2 and similarly for the rest of the columns.</p>
<p><strong>How will you solve this? </strong></p>
<p>Solution 1: Write an itemRenderer for each column and code the logic for formatting in the indvidual renderers.</p>
<p>Solution 2: Write a single itemRenderer for all the columns which will achieve conditional formatting based on the columnIndex.</p>
<p>Practically, both this solutions can bee used but for many simple formatting cases, writing a single itemRenderer will be a much more robust solution. The example that I am illustrating below adopts the methodology mentioned in solution 2.In this simple example, I have used an itemRenderer called customItemRenderer to display different data across different columns in a DataGrid. Based on the columnIndex , the datagrid will display 3 different smiley&#8217;s in its 3 columns.</p>
<p>Please note that this kind of approach will be strictly tied to column indices and hence a situation where you have to use column dragging and reordering this methodology will not be useful. In the example, I have set draggableColumns=false.</p>
<p>Let us look in to the main application code:</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br />
&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; creationComplete=&#8221;populateData()&#8221; viewSourceURL=&#8221;srcview/index.html&#8221;&gt;<br />
&lt;mx:Script&gt;<br />
&lt;![CDATA[<br />
//DataGrid event, fired when the itemEditing is performed<br />
import mx.events.DataGridEvent;<br />
//Used for populating the datagrid<br />
import mx.collections.ArrayCollection;<br />
//Used to display the Alert<br />
import mx.controls.Alert;<br />
//ArrayCollection that will hold the data<br />
[Bindable]private var arr:ArrayCollection<br />
private function populateData():void<br />
{</p>
<p>//Create an arraycollection<br />
arr = new ArrayCollection()<br />
//Loop to create 10 records<br />
for(var i:int=0;i&lt;10;i++)<br />
{</p>
<p>//Create an object to insert into the array collection<br />
var obj:Object = {col1:i, col2:i,col3:i}<br />
//Add the object to array collection<br />
arr.addItem(obj)<br />
}</p>
<p>}</p>
<p>]]&gt;<br />
&lt;/mx:Script&gt;<br />
&lt;!&#8211; DataGrid Instance, dataProvider is bound to &#8216;arr&#8217;- the arraycollection. &#8211;&gt;<br />
&lt;mx:DataGrid draggableColumns=&#8221;false&#8221; variableRowHeight=&#8221;true&#8221; wordWrap=&#8221;true&#8221; editable=&#8221;true&#8221; id=&#8221;datagrid&#8221; x=&#8221;56&#8243; y=&#8221;104&#8243; height=&#8221;176&#8243; width=&#8221;317&#8243; dataProvider=&#8221;{arr}&#8221; themeColor=&#8221;#CECECE&#8221;&gt;<br />
&lt;mx:columns&gt;<br />
<strong>    &lt;mx:DataGridColumn headerText=&#8221;Column 1&#8243; dataField=&#8221;col1&#8243; itemRenderer=&#8221;customItemRenderer&#8221;/&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Column 2&#8243; dataField=&#8221;col2&#8243; itemRenderer=&#8221;customItemRenderer&#8221;/&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Column 3&#8243; dataField=&#8221;col3&#8243; itemRenderer=&#8221;customItemRenderer&#8221;/&gt;</strong><br />
&lt;/mx:columns&gt;<br />
&lt;/mx:DataGrid&gt;</p>
<p>&lt;/mx:Application&gt;</p></blockquote>
<p>There are 3 datagrid columns and each of them have the same itemRenderer assigned to them.<br />
Well , that was fairly straight forward. Now lets take a look at the itemRenderer code. Thats where most of the action is <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br />
<strong>&lt;mx:Canvas xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; width=&#8221;182&#8243; height=&#8221;30&#8243; implements=&#8221;mx.controls.listClasses.IDropInListItemRenderer&#8221; horizontalScrollPolicy=&#8221;off&#8221;&gt;</strong><br />
&lt;mx:Script&gt;<br />
&lt;![CDATA[<br />
import mx.controls.listClasses.BaseListData;<br />
import mx.controls.dataGridClasses.DataGridListData;<br />
protected var _listData:DataGridListData;<br />
override public function set data(value:Object):void<br />
{<br />
setIt(value);<br />
}<br />
public function get listData():BaseListData<br />
{<br />
return _listData;<br />
}<br />
public function set listData(value:BaseListData):void<br />
{<br />
_listData = DataGridListData(value);<br />
invalidateProperties();<br />
}<br />
private function setIt(value:Object):void<br />
{<br />
if(value &amp;&amp; _listData)<br />
{<br />
if(_listData.columnIndex == 0)<br />
{<br />
img.source="a.gif"<br />
}<br />
else if(_listData.columnIndex == 1)<br />
{<br />
img.source="b.gif"<br />
}<br />
else<br />
{<br />
img.source="c.gif"<br />
}<br />
}<br />
}</p>
<p>]]&gt;<br />
&lt;/mx:Script&gt;<br />
&lt;mx:Image x=&#8221;10&#8243; y=&#8221;6&#8243; width=&#8221;20&#8243; height=&#8221;20&#8243; id=&#8221;img&#8221;/&gt;<br />
&lt;/mx:Canvas&gt;</p></blockquote>
<p>Look at the first line of the itemRenderer code. for getting access to the _listData property we have to implement the interface <strong>IDropInListItemRenderer, </strong>which has two methods.</p>
<p>public function get listData():BaseListData<br />
{<br />
return _listData;<br />
}<br />
public function set listData(value:BaseListData):void<br />
{<br />
_listData = DataGridListData(value);<br />
invalidateProperties();<br />
}</p>
<p>The _listData object holds the property <strong>columnIndex</strong>, which tells you which column does the itemRenderer belong to. Once you have the columnIndex, write your conditional logic to display corresponding data. In this case I am setting a smiley to the image control in the itemRenderer based on the columnIndex.</p>
<p>This can be extended to any level of conditional formatting too <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong><a href="http://www.geocities.com/harishsivaram/itemrendererEx2.swf" target="_blank">View sample application</a> | <a href="http://www.geocities.com/harishsivaram/itemrendererex.zip">Download source</a> </strong></p>
<blockquote></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexgeek.in/2007/05/tutorial-using-same-itemrenderer-for-multiple-columns/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Tips &amp; Tricks &#8211; ItemEditors &#8211; II</title>
		<link>http://blog.flexgeek.in/2007/05/tips-tricks-itemeditors-ii/</link>
		<comments>http://blog.flexgeek.in/2007/05/tips-tricks-itemeditors-ii/#comments</comments>
		<pubDate>Thu, 10 May 2007 09:40:41 +0000</pubDate>
		<dc:creator>vodka</dc:creator>
				<category><![CDATA[tips & tricks]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://flexgeek.wordpress.com/2007/05/10/tips-tricks-itemeditors-ii/</guid>
		<description><![CDATA[We saw in the earlier article about using itemEditors in a flex datagrid. Now, Lets dive a little deeper into doing some more complex things with itemEditors in a flex datagrid. Before we get started, let us get introduced to the events that are most critical when we are performing an edit operation in a [...]]]></description>
			<content:encoded><![CDATA[<p>We saw in the <a href="http://flexgeek.wordpress.com/2007/04/09/tips-tricks-itemeditors-i/" target="_blank">earlier article</a> about using itemEditors in a flex datagrid. Now, Lets dive a little deeper into doing some more complex things with itemEditors in a flex datagrid. Before we get started, let us get introduced to the events that are most critical when we are performing an edit operation in a flex datagrid.</p>
<p>(Description of each of these events are available in the livedocs, readers are requested to check up)</p>
<p><strong>itemEditBegin</strong> &#8211;  Fired when you click on an editable cell of the datagrid (also when the editedItemPosition is set on an editable DataGrid)</p>
<p><strong>itemEditBeginning </strong>- Fired when the mouse is released</p>
<p><strong>itemEditEnd </strong>- Fired when the edit is committed / editor is destroyed there by terminating the edit session.</p>
<p>Now, Lets get back to our scenario. Let us take a simple example &#8211; We have a datagrid with a numeric stepper used as an itemEditor similar to the example stated in the part I of this article. Now, let us add an additional functionality of adding a validation to the data that gets entered in the itemEditor.  Take a look at the example attached along with this post to see this in action.</p>
<p><strong>Let us dig into the code now: </strong></p>
<blockquote><p>&lt;mx:DataGrid editable=&#8221;true&#8221; id=&#8221;datagrid&#8221; x=&#8221;105&#8243; y=&#8221;85&#8243; height=&#8221;176&#8243; width=&#8221;317&#8243; dataProvider=&#8221;{arr}&#8221; <em><strong>itemEditEnd=&#8221;doValidation(event)&#8221;</strong></em>&gt;<br />
&lt;mx:columns&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Data&#8221; dataField=&#8221;disp&#8221; editable=&#8221;false&#8221;/&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Available&#8221; dataField=&#8221;value&#8221; editable=&#8221;false&#8221;/&gt;<br />
&lt;!&#8211; itemEditor is set to our class CustomNumericStepper. Always remember to set the editorDataField to the dataField on which the operation is performed&#8211;&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Order Qty&#8221; dataField=&#8221;order&#8221; itemEditor=&#8221;CustomNumericStepper&#8221; editorDataField=&#8221;value&#8221;/&gt;</p>
<p>&lt;/mx:columns&gt;<br />
&lt;/mx:DataGrid&gt;</p></blockquote>
<p>when the itemEditEnd event of the DataGrid fires, we invoke a method call doValidation() which performs the validation of rhe data entered in the editor. So,whats the logic for validation? We validate if the new value that is getting entered in the column is less than or equal to the value in the available column. on fail, we will throw an alert indicating the error to the user. showError() method is used to achieve this.</p>
<blockquote><p>//Validate the data entered / stepped in the itemEditor<br />
private function doValidation(event:DataGridEvent):void<br />
{</p>
<p>//Storing the selection made in the itemEditor to a variable<br />
var selectedData:Object = CustomNumericStepper(datagrid.itemEditorInstance).value<br />
//Store the upper bound to compare<br />
var upperBound:Number = event.target.selectedItem.value;<br />
//Compare if the entered value is &gt; upper bound<br />
if(selectedData &gt; upperBound)<br />
{<br />
//Destroy the instance of the itemEditor by calling destroyEditor()<br />
datagrid.destroyItemEditor()<br />
//Call preventDefault() so that the new value is NOT committed<br />
event.preventDefault();<br />
//Invoke a method to display an error message<br />
showError(upperBound);<br />
}<br />
}<br />
//Display the error message<br />
private function showError(value:Number):void<br />
{<br />
//Show the error message in an Alert Box<br />
Alert.show(&#8220;Please Enter a value less than &#8220;+value)<br />
}</p></blockquote>
<blockquote></blockquote>
<p><strong>So, whats doValidation() doing? </strong></p>
<p>doValidation() receives the datagrid event as its parameter. The first step is to store the Object corresponding the edited item into a variable &#8211; <strong>selectedData </strong></p>
<p>Now we find out what is the upper bound to validate against. This is the value in the available column for the current record that we are editing. Now we store that value to another variable &#8211; <strong>upperBound </strong></p>
<p>Lets check if selectedData &gt; uppedBound. On this condition being satisfied, we do the following steps.</p>
<p>Destroy the editor instance &#8211; <strong>destroyItemEditor() </strong>is called. This is to close the editor<br />
Prevent committing of the data &#8211; <strong>event.preventDefault()</strong> is called. This prevents the default action that a particular event triggers. In this case, the committing of the data is prevented.<br />
Finally, showError() method is called to alert the error message to the user.</p>
<p>There we go! We have a simple working sample of applying a validation to an itemEditor of a flex datagrid up and running.</p>
<p><strong><a href="http://www.geocities.com/harishsivaram/itemEditorEx3.swf" target="_blank">View Sample</a> | <a href="http://www.geocities.com/harishsivaram/itemEditorExample-II.zip" target="_blank">Download Source</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexgeek.in/2007/05/tips-tricks-itemeditors-ii/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Tips &amp; Tricks : itemEditors  &#8211; I</title>
		<link>http://blog.flexgeek.in/2007/04/tips-tricks-itemeditors-i/</link>
		<comments>http://blog.flexgeek.in/2007/04/tips-tricks-itemeditors-i/#comments</comments>
		<pubDate>Mon, 09 Apr 2007 10:09:39 +0000</pubDate>
		<dc:creator>vodka</dc:creator>
				<category><![CDATA[tips & tricks]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://flexgeek.wordpress.com/2007/04/09/tips-tricks-itemeditors-i/</guid>
		<description><![CDATA[Alex has written two wonderful posts in his blog about working with itemRenderers. Along with itemRenderers another extremely useful feature in flex is itemEditors. itemEditors provide a highly efficient and clean way of providing custom editors for editing data in components like List and DataGrid. Take this example: You have a Datagrid with two columns [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://blogs.adobe.com/aharui" target="_blank">Alex</a></strong> has written two wonderful <strong><a href="http://blogs.adobe.com/aharui" target="_blank">posts</a></strong> in his blog about working with <strong>itemRenderers</strong>. Along with itemRenderers another extremely useful feature in flex is <strong>itemEditors</strong>. itemEditors provide a highly efficient and clean way of providing custom editors for editing data in components like List and DataGrid.</p>
<p>Take this example: You have a Datagrid with two columns (Product, Available and Order Qty). Avaliable &amp; Order Qty columns contain  numeric data. You want to allow the user to make an order by selecting the Order Qty column by entering a value for the number of pieces he wants to order in the column.</p>
<p><strong>Option 1</strong>: You can simply pop the default itemEditor of a Datagrid / List, which is a <strong>TextInput </strong>where the user can key in the number.<br />
<strong>Option 2</strong>: You can pop a custom itemEditor.In this case, using a <strong>NumericStepper</strong> makes a lot of sense because it lets the user increment / decrement a value and also allow him to type in just like in a textinput.</p>
<p>I have used <strong>Option 2</strong>, to implement the solution.</p>
<p><strong>So, Why itemEditors and not itemRenderers?</strong><br />
You can  set a NumericStepper as an <strong>itemRenderer </strong>and set the <strong>rendererIsEditor </strong>property to true. But in that case the renderers are pre-created, they are <strong>*always*</strong> displayed evcen when you are not editing it and lastly, you have to write your own logic to persist the data after editing the cell. (That surely seems like more work than using itemEditors for our current problem.)</p>
<p><strong>Lets Get back to itemEditors </strong>-  Take a look at the example attached along with this post which uses a NumericStepper as its itemEditor. You can see that the NumericStepper is popped when you click on the cell in the Order Qty column and the editor is destroyed when you click on anywhere else / change the focus. Also note that the value that you entered / stepped is now committed and the DataGrid display is updated.</p>
<p><strong>Lets do a little digging into the code <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </strong><br />
As you can see, there is *very little* code that is written to implement this solution.</p>
<p><strong>Step 1 &#8211; Set up the data</strong>: (see inline code comments)</p>
<blockquote><p>           //DataGrid event, fired when the itemEditing is performed<br />
import mx.events.DataGridEvent;<br />
//Used for populating the datagrid<br />
import mx.collections.ArrayCollection;<br />
//Used to display the Alert<br />
import mx.controls.Alert;<br />
//ArrayCollection that will hold the data<br />
[Bindable]private var arr:ArrayCollection<br />
private function populateData():void<br />
{<br />
//Create an array with dummy product names<br />
var prodarray:Array =   ['Apple','Orange','Peach','Grapes','Guava','Mango','Raspberry','Strawberry','Watermelon','Passionfruit']<br />
//Create an arraycollection<br />
arr = new ArrayCollection()<br />
//Loop to create 10 records<br />
for(var i:int=0;i&lt;10;i++)<br />
{<br />
//create a random number<br />
var rnd:Number = Math.round(Math.random()*100);<br />
//Create an object to insert into the array collection<br />
var obj:Object = {value:rnd, disp:prodarray[i],order:0}<br />
//Add the object to array collection<br />
arr.addItem(obj)<br />
}</p>
<p>}</p></blockquote>
<p><strong>Step 2: Create the Datagrid and set up the itemEditor.</strong></p>
<p>The following lines of code create an instance of Datagrid with 3 columns, and we set the itemEditor and editorDataField properties to the third column. (See inline comments)</p>
<p>One important point to be remembered here. The DataGrid or List always looks for the default property <strong>text </strong>on the itemEditors unless you specify the editorDataField property to the appropriate value. In this case editorDataField will be <strong>value </strong> since we will be altering the value property when we increment / decrement a NumericStepper. If we were to use a TextArea, the property should be set to <strong>text</strong>. If you forget to set this property, then prepare yourself for some erratic behavior <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>&lt;!&#8211; DataGrid Instance, dataProvider is bound to &#8216;arr&#8217;- the arraycollection. &#8211;&gt;<br />
&lt;mx:DataGrid editable=&#8221;true&#8221; id=&#8221;datagrid&#8221; x=&#8221;56&#8243; y=&#8221;104&#8243; height=&#8221;176&#8243; width=&#8221;317&#8243; dataProvider=&#8221;{arr}&#8221;&gt;<br />
&lt;mx:columns&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Product&#8221; dataField=&#8221;disp&#8221;/&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Available&#8221; dataField=&#8221;value&#8221;/&gt;<br />
&lt;!&#8211; itemEditor is set to our class CustomNumericStepper. Always remember to set the editorDataField to the dataField on which the operation is performed&#8211;&gt;<br />
&lt;mx:DataGridColumn headerText=&#8221;Order Qty&#8221; dataField=&#8221;order&#8221; itemEditor=&#8221;CustomNumericStepper&#8221; editorDataField=&#8221;value&#8221; /&gt;<br />
&lt;/mx:columns&gt;<br />
&lt;/mx:DataGrid&gt;</p></blockquote>
<p><strong>Step 3: Create the custom itemEditor </strong></p>
<p>I have created a CustomNumericStepper class which extends from NumericStepper. (CustomNumericStepper.as). This class contains just two properties, the maximum and the stepSize. The maximum is set to 150, assuming that we will *not* be stocking more than 150 fruits of each type (well, we will change this assumption soon, accommodating a more realistic calculation, but lets keep it this way for the sake of simplicity <img src='http://blog.flexgeek.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<blockquote><p>package<br />
{<br />
import mx.controls.NumericStepper;</p>
<p>public class CustomNumericStepper extends NumericStepper<br />
{<br />
public function CustomNumericStepper():void<br />
{<br />
super();<br />
//Set the properties<br />
stepSize=1;<br />
maximum=150;<br />
}<br />
}<br />
}</p></blockquote>
<p>Note: I chose to write this as a .as file, you could very well use an  MXML component to achieve the same results.</p>
<p>We are all set to go! <a href="http://www.geocities.com/harishsivaram/itemEditorEx2.swf"></a></p>
<p><strong><a href="http://www.geocities.com/harishsivaram/itemEditorEx2.swf" target="_blank">View the Sample</a> | <a href="http://www.geocities.com/harishsivaram/itemEditorEx2.zip">Download Source</a> </strong></p>
<p><a href="http://www.geocities.com/harishsivaram/itemEditorEx2.swf"></a>and right click on the application to view / download the full source.</p>
<p>Coming up next: Doing more with itemEditors &#8211; applying formatters &amp; validators to itemEditors</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexgeek.in/2007/04/tips-tricks-itemeditors-i/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Alex Harui&#8217;s Flex Blog</title>
		<link>http://blog.flexgeek.in/2007/03/alex-haruis-flex-blog/</link>
		<comments>http://blog.flexgeek.in/2007/03/alex-haruis-flex-blog/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 09:15:45 +0000</pubDate>
		<dc:creator>vodka</dc:creator>
				<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://flexgeek.wordpress.com/2007/03/30/alex-haruis-flex-blog/</guid>
		<description><![CDATA[Alex Harui from the Flex SDK Engineering team of Adobe USA has started a blog. The blog can be accessed at the following location. http://blogs.adobe.com/aharui/ The Blog contains some extremely easy to follow explanations, some great code snippets and examples.Alex is some one almost every flex engineering team guy at Adobe looks upto for their [...]]]></description>
			<content:encoded><![CDATA[<p>Alex Harui from the Flex SDK Engineering team of Adobe USA has started a blog. The blog can be accessed at the following location.</p>
<p><a href="http://blogs.adobe.com/aharui/" target="_blank"><strong> http://blogs.adobe.com/aharui/</strong></a></p>
<p>The Blog contains some extremely easy to follow explanations, some great code snippets and examples.Alex is some one almost every flex engineering team guy at Adobe looks upto for their flex related issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexgeek.in/2007/03/alex-haruis-flex-blog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
