3.2 Attribute Table copy

1639
2
04-22-2013 07:46 AM
KennyHoran
New Contributor III
My users like the Attribute Table but they'd really like to copy data from the Attribute Table and paste it elsewhere.  Might I place an enhancement request for this feature?

Alternately I see an Event.COPY event fires on the Attribute Table when a user presses Ctl+C, but now I'm stuck on how to get at the data.  How do I access the selected items in an Attribute Table?

Edit: Found the selected items in AttributeTable.featureLayer.selectedFeatures
Tags (2)
0 Kudos
2 Replies
SarthakDatt
Occasional Contributor III
Hey Kenny,

If you look under the 'Table Options' menu, there is a way to export the data to a CSV file. If there are any features selected it would only export those, otherwise the entire feature set.
0 Kudos
KennyHoran
New Contributor III
That's handy but just doesn't cut it (pun intended). My users want a simple Ctrl+C just like how Excel works. Here's an extension I wrote to illustrate.

<?xml version="1.0" encoding="utf-8"?>
<!--
AttributeTableWidget extension for ArcGIS Flex Viewer 3.2
Adds copy feature to Attribute Table via keyboard and right-click menu.
To use, configure the AttributeTable widget and substitute this file for "AttributeTableWidget.mxml" in your config.xml
-->
<AttributeTable:AttributeTableWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:AttributeTable="widgets.AttributeTable.*"
         widgetConfigLoaded="basewidget_widgetConfigLoaded()">

 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.components.AttributeTable;

   import flash.events.ContextMenuEvent;

   import spark.components.NavigatorContent;


   /** Listen for new AttributeTables being added to viewStack */
   private function basewidget_widgetConfigLoaded():void
   {
    viewStack.addEventListener(ChildExistenceChangedEvent.CHILD_ADD, childAddEvent);
   }

   /** Add copy listener and menu item to the new AttributeTable */
   private function childAddEvent(event:ChildExistenceChangedEvent):void
   {
    var attributeTable:AttributeTable = (event.relatedObject as NavigatorContent).getElementAt(0) as AttributeTable;

    attributeTable.addEventListener(Event.COPY, attributeTable_copyHandler);

    var contextMenu:ContextMenu = new ContextMenu();
    contextMenu.hideBuiltInItems();
    var customItem:ContextMenuItem = new ContextMenuItem("Copy selected");
    customItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, customItem_menuItemSelectHandler);
    contextMenu.customItems.push(customItem);
    attributeTable.contextMenu = contextMenu;
   }

   /** Copy selected rows to the clipboard Excel style */
   private function attributeTable_copyHandler(event:Event):void
   {
    var rows:Array = [];
    for each (var graphic:Graphic in (event.currentTarget as AttributeTable).featureLayer.selectedFeatures)
    {
     var newRow:Array = [];
     for each (var value:String in graphic.attributes)
      newRow.push(value);
     rows.push(newRow.join("\t"));
    }
    System.setClipboard(rows.join("\r\n"));
   }

   /** Dispatch a COPY event when clicked */
   private function customItem_menuItemSelectHandler(event:ContextMenuEvent):void
   {
    (event.contextMenuOwner as AttributeTable).dispatchEvent(new Event(Event.COPY));
   }
  ]]>
 </fx:Script>
</AttributeTable:AttributeTableWidget>


It'd be great to have a similar capability in a future release. This code is retyped, so I apologize in advance for any typos.
0 Kudos