<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.35459-</id>
  <updated>2009-11-16T15:13:48Z</updated>
  <title>Comments for Custom Renderers for the Flex AdvancedDataGrid (http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.35459</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=35459" title="Custom Renderers for the Flex AdvancedDataGrid" />
    <published>2009-03-01T14:00:00Z</published>
    <updated>2009-08-09T20:11:05Z</updated>
    <title>Custom Renderers for the Flex AdvancedDataGrid</title>
    <summary> There are hardly any code example for how to use renderers for AdvancedDataGrid, and those that do exist are trivial. Apparently AdvancedDataGrid has issues, according to none other than the illustrious Doug McCune: As a very general word of...</summary>
    <author>
      <name>Mike Slinn</name>
      <uri>http://mslinn.com</uri>
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<p><br />
There are hardly any code example for how to use renderers for AdvancedDataGrid, and those that do exist are trivial. Apparently <tt>AdvancedDataGrid</tt> has issues, according to none other than the illustrious <a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg96642.html">Doug McCune</a>:</p>

<blockquote><i>As a very general word of warning, I'd advise you to be more careful and expect more pain when working with the following classes (and all associated base classes, etc): AdvancedDataGrid, OLAPDataGrid, GroupingCollection.<br /><br />
I'll try to be extremely politically correct here, but I assume you'll catch my drift... These classes were written by a different part of the Flex team, in a different part of the world, and they are quite different than the standard Flex framework code base. They often don't follow the same coding standards, and in my opinion they are not up to the same quality level that I have come to expect from the Flex framework. I'll stop at that before I make too many Adobeans mad at me, but just know that I've learned to expect a whole new kind of pain when working with those classes.</i></blockquote>

<p>My customer was not interested in excuses; he wanted me to produce working item and edit renderers for an <tt>AdvancedDataGrid</tt>, and soon. After some experimentation, I discovered an elegant solution that I would like to share with you, gentle reader.</p>

<p>One way that <tt>AdvancedDataGridColumn</tt> differs from <tt>DataGridColumn</tt> is that the default <tt>itemEditor</tt> will not  activate if an <tt>itemRenderer</tt> is specified. The default values for the relevant <tt>AdvancedDataGridColumn</tt> properties do work, and I relied on that when figuring out how to make custom renderers work:<br />
</p><ul><br />
  <li><tt>dataField="data"</tt></li><br />
  <li><tt>rendererIsEditor="false"</tt></li><br />
  <li><tt>itemEditor="mx.controls.TextInput"</tt></li><br />
  <li><tt>itemRenderer="mx.controls.Label"</tt></li><br />
</ul>

<p>As you can see, the <tt>itemRenderer</tt> and <tt>editRenderer</tt> need not extend <tt>AdvancedDataGridItemRenderer</tt>; they may extend any <tt>UIComponent</tt> subclass.</p>

<p>In ActionScript, specify the <tt>AdvancedDataGridColumn</tt> renderers like this:<br />
</p><pre>var column:AdvancedDataGridColumn = new AdvancedDataGridColumn();<br />
column.dataField = "whatever";<br />
column.headerText = "blah blah";<br />
column.editable = true;<br />
column.itemEditor = new ClassFactory(TextInput);<br />
column.itemRenderer = new ClassFactory(CustomAdvancedDataGridItemRenderer);</pre>

<p><br />
The <tt>AdvancedDataGridColumn.rendererIsEditor</tt> property should only be set <tt>true</tt> when the same class is used for both types of renderers.  As you can see, the default renderer classes are different from each other.</p>

<p>The secret to getting <tt>AdvancedDataGrid</tt> to behave when you want to spacify one of the renderers is to specify both of them. To illustrate this, I put together a short demo application that features an <tt>AdvancedDataGrid </tt>with two columns. The right-hand column uses the default <tt>itemEditor</tt> and <tt>itemRenderer</tt> classes (<tt>TextInput</tt> and <tt>Label</tt>). The left-hand column uses a custom <tt>AdvancedDataGridItemRenderer</tt> for the <tt>itemRenderer</tt>, and a <tt>TextInput</tt> for the <tt>itemEditor</tt>.</p>

<p>Going one step further, I wanted to change the default selection / edit mouse behavior. By default, when edit mode is enabled, <tt>DataGrid</tt> and <tt>AdvancedDataGrid</tt> both immediately enter edit mode with a single click. Instead, I wanted a single click to select a row, and a double-click to edit a cell. After providing a double-click event handler, I discovered that the double-click interval that Adobe provides was unusable. To solve this problem, I used <tt>flash.utils.Timer</tt> to implement my own double-click detection logic with only five lines of code. Because I did not use the default Flex double-click handler, I did not specify <tt>doubleClickEnabled="true"</tt>.</p>

<p><a href="http://www.mslinn.com/index.jsp?sites/flex/ADGEditTest/ADGEditTest.html">Here</a> is a demo web application that illustrates how this all works, with view source enabled. Check it out!</p>
<p>_______________________________</p>
<p>Mike Slinn<br />
Independent full-service software contractor and author<br />
<a href="http://slinnbooks.com/">http://slinnbooks.com</a><br />
<a href="http://www.mslinn.com/">http://mslinn.com</a></p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054343</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054343" />
    <title>Comment from Prabhuram Baskaran on 2009-03-02</title>
    <author>
        <name>Prabhuram Baskaran</name>
        <uri>http://www.produle.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.produle.com">
        <![CDATA[<p>This article is very useful. On a relevant note, users can test custom renderers using an online flash builder called produle.com that provides a data table component (based off the advanced data grid) which supports item renderers, data grouping..., an example created with it <a href="http://tinyurl.com/cr98cu">http://tinyurl.com/cr98cu</a></p>]]>
    </content>
    <published>2009-03-02T16:53:57Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054364</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054364" />
    <title>Comment from Damian on 2009-03-02</title>
    <author>
        <name>Damian</name>
        <uri>http://www.andensolutions.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.andensolutions.com">
        <![CDATA[<p>Thanks for the article. Now I'll know what to do when presented with this case! One thing though, I believe that the sentence: <br />
"The left-hand column uses a custom AdvancedDataGridItemRenderer for the itemEditor, and a TextInput for the itemEditor." <br />
should read:<br />
The left-hand column uses a custom AdvancedDataGridItemRenderer for the <b>itemRenderer</b> , and a TextInput for the itemEditor.<br />
</p>]]>
    </content>
    <published>2009-03-02T22:01:41Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054365</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054365" />
    <title>Comment from Mike Slinn on 2009-03-02</title>
    <author>
        <name>Mike Slinn</name>
        <uri>http://mslinn.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://mslinn.com">
        <![CDATA[<p>Thanks, Damian.  I corrected the sentence.</p>]]>
    </content>
    <published>2009-03-02T22:05:32Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054371</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054371" />
    <title>Comment from Dan on 2009-03-02</title>
    <author>
        <name>Dan</name>
        <uri>http://www.familytreedna.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.familytreedna.com">
        <![CDATA[<p>This is a great article, but how would this apply to a headerrenderer? We are currently tackling a memory leak where we end up with hundreds of instances of our customer header by simply scrolling the grid left and right (using the Flex Profiler to see this) on a 32 column datagrid. We simply extended AdvancedDataGridHeaderRenderer to add our customizations. While debugging I noticed it never actually calls the newInstance method which we believe is used by the ClassFactory to create new instances. If you could perhaps give some guidance that would be great!</p>

<p>Thanks,</p>

<p>Dan</p>]]>
    </content>
    <published>2009-03-02T23:34:17Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054372</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054372" />
    <title>Comment from Dan on 2009-03-02</title>
    <author>
        <name>Dan</name>
        <uri>http://www.familytreedna.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.familytreedna.com">
        <![CDATA[<p>This is a great article, but how would this apply to a HeaderRenderer? We are currently tackling a memory leak where we end up with hundreds of instances of our custom header by simply scrolling the grid left and right (using the Flex Profiler to see this) on a 32 column datagrid. We simply extended AdvancedDataGridHeaderRenderer to add our customizations. While debugging I noticed it never actually calls the newInstance method which we believe is used by the ClassFactory to create new instances. If you could perhaps give some guidance that would be great!</p>

<p>Thanks,</p>

<p>Dan</p>]]>
    </content>
    <published>2009-03-02T23:35:08Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054374</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054374" />
    <title>Comment from Mike Slinn on 2009-03-02</title>
    <author>
        <name>Mike Slinn</name>
        <uri>http://mslinn.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://mslinn.com">
        <![CDATA[<p>Dan,</p>

<p>I'd have to look at your code to help.  My contact info is here: <a href="http://www.mslinn.com/">http://www.mslinn.com/</a></p>

<p>Mike</p>]]>
    </content>
    <published>2009-03-02T23:39:47Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2054403</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2054403" />
    <title>Comment from Dan on 2009-03-03</title>
    <author>
        <name>Dan</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Mark,</p>

<p>Actually turns out to be an Adobe bug. <a href="http://bugs.adobe.com/jira/browse/FLEXDMV-1968">http://bugs.adobe.com/jira/browse/FLEXDMV-1968</a></p>

<p>I'm going to try and create a custom renderer from scratch without extending AdvancedDataGridHeaderRenderer. </p>

<p>Thanks,</p>

<p>Dan</p>]]>
    </content>
    <published>2009-03-03T14:04:08Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2055427</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2055427" />
    <title>Comment from Sunny on 2009-03-18</title>
    <author>
        <name>Sunny</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Sorry, but i didn't see source on<br />
<a href="http://www.mslinn.com/index.jsp?sites/flex/ADGEditTest/ADGEditTest.html">http://www.mslinn.com/index.jsp?sites/flex/ADGEditTest/ADGEditTest.html</a><br />
could you give some help?</p>

<p><br />
</p>]]>
    </content>
    <published>2009-03-18T10:40:57Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2055658</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2055658" />
    <title>Comment from Mike Slinn on 2009-03-20</title>
    <author>
        <name>Mike Slinn</name>
        <uri>http://mslinn.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://mslinn.com">
        <![CDATA[<p>Right-click on the application and select the "View Source" menu item.  This is a common Flex feature.</p>]]>
    </content>
    <published>2009-03-21T00:48:24Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2058084</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2058084" />
    <title>Comment from Daniel La Buonora on 2009-04-21</title>
    <author>
        <name>Daniel La Buonora</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>hey, what if when editing you want to jump into the next cell with tab button, this solution prevents from that.<br />
any workaround??</p>]]>
    </content>
    <published>2009-04-22T03:44:25Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2059912</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2059912" />
    <title>Comment from Ram Tallapaka on 2009-05-19</title>
    <author>
        <name>Ram Tallapaka</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>How well does these custom renderers work with Flex automation tools? I am not a Flex Developer, but an automation engineer trying to automate few clicks on a DataGrid that has custom renderes. <br />
Our developers extended the class mx.controls.dataGridClasses.DataGridItemRenderer and added some simple customization. QTP (the automation tool with Flex addin supplied by Adobe), is really inconsistent in recognizing this object. It's supposed to recognize it as "FlexListLabel", but it's identifying it as "FlexLabel" and there by causing issues. </p>

<p>It worked fine once developers removed the customization.  Any suggestions?</p>

<p>Thanks<br />
Ram</p>]]>
    </content>
    <published>2009-05-19T17:42:01Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35459-comment:2099068</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35459" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/03/custom-edit-renderers-for-the.html#comment-2099068" />
    <title>Comment from Matt on 2009-09-15</title>
    <author>
        <name>Matt</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Very informative article here, thankyou; it definitely helped me with the 2 AdvancedDataGrids I'm using in my app right now. And I had spent a day or so reading Doug's post (and the longer email trail that it is included in) when I was dealing with the AdvancedDataGridGroupItemRenderer and the AdvancedDataGridItemRenderer for other columns. </p>

<p>However, I'm having trouble performing my next task; that is when a row is collapsed, I want the row to collapse only halfway, not fully. When expanded, it displays a horizontal list of charts. On collapse, I want it to display the same row with half the height. </p>

<p>I was wondering, is this possible? Do I have to override displayItemsExpanded()? Can I use a dataProvider where some elements are groups and some are not? </p>]]>
    </content>
    <published>2009-09-15T14:58:15Z</published>
  </entry>

</feed
