<?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("")); } /** 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>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.