Trick to copy data from a Flex AdvancedDataGrid

Here’s a small trick to allow copying individual cell data from a Flex AdvancedDataGrid.

When using a non editable Flex AdvancedDataGrid supporting selection, there’s no default way of just copying the content of a given cell.

The easiest trick I found consists in setting the AdvancedDataGrid as being editable and defining as an itemEditor a simple TextInput configured as not being editable and with its content selected!

In other words:

Ensure your AdvancedDataGrid is defined as editable:

<mx:AdvancedDataGrid editable="true" dataProvider="{gridData}">

Define a non editable TextInput selecting its content:

<mx:Component className="NonEditableTextInput">
    <mx:TextInput editable="false"
        selectionBeginIndex="0" selectionEndIndex="{text.length}"/>
</mx:Component>

And use it as an itemEditor for your AdvancedDataGrid:

<mx:AdvancedDataGridColumn dataField="Field" itemEditor="NonEditableTextInput"/>

Now, when clicking in any cell of the AdvancedDataGrid, the non editable TextInput is displayed with its content selected and ready for copy.

Here’s a working example (with source code available):

In addition, let me take this post as an opportunity to mention a very useful utility site: Mr. Data Converter. Just paste CSV or tab delimited data and it will convert your data into one of several web-friendly formats, including XML, HTML, PHP and.. ActionScript! This is really a good tool when you want to generate some test data for a Flex AdvancedDataGrid in a few seconds :-D

VN:F [1.9.8_1114]
Rating: 5.0/5 (4 votes cast)
Trick to copy data from a Flex AdvancedDataGrid, 5.0 out of 5 based on 4 ratings
  1. Jim
    July 4th, 2011 at 09:17 | #1

    Do you also have an spark version (Flex 4), tnx!?

    VA:F [1.9.8_1114]
    Rating: 5.0/5 (2 votes cast)
  2. Prateek
    September 13th, 2011 at 12:50 | #2

    Really nice way of doing it. Thanks. I was looking just for this.

    VA:F [1.9.8_1114]
    Rating: 5.0/5 (1 vote cast)
  3. koganti
    October 28th, 2011 at 09:20 | #3

    How about copying data which is hierarchical?Its not supporting for tht.

    VA:F [1.9.8_1114]
    Rating: 5.0/5 (1 vote cast)
  4. Pal
    May 27th, 2013 at 07:47 | #4

    Hi Is there any way to select all and copy instead of single cell.

    VA:F [1.9.8_1114]
    Rating: 0.0/5 (0 votes cast)
  1. October 31st, 2010 at 22:44 | #1
Put ActionScript or MXML code snippets between tags: [as3][/as3]
You can also resize the comment area by dragging the bottom right corner.