HelloI am new to flex so this is one of my first attempts. My widget selects a sign (from a Feature Layer) and the returns the related inspection data (from a Feature Layer called Inspection) in a grid. Ideally I want to be able to edit the attributes of the related inspection table in the data grid.I have had a look at the edit related tables example and the attribute inspector but I am unsure which route to go down. Is it possible with the AttributeInspector to edit results from a relationship query in a grid? E.g. We want to be able to select a site and view all of the outstanding maintenance issues related to it in a table, and assign each issue to a team and commment on it. Opposed to selecting each issue separatley to edit it.Can anyone point me in the directon of a example of how to feature layer attributes within a datagrid?Thank youVicky<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:viewer="com.esri.viewer.*"
widgetConfigLoaded="init()"
xmlns:esri="http://www.esri.com/2008/ags">
<fx:Script>
<![CDATA[
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.events.*;
import com.esri.ags.symbols.*;
import com.esri.ags.tools.DrawTool;
import com.esri.ags.geometry.Geometry;
import mx.controls.Alert;
import com.esri.ags.tasks.supportClasses.*;
import com.esri.ags.layers.*;
import com.esri.ags.geometry.Extent;
import com.esri.ags.SpatialReference;
import com.esri.ags.FeatureSet;
import mx.rpc.AsyncResponder;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.events.FeatureLayerEvent;
var graphicsLayer:GraphicsLayer;
var sym:Symbol;
var flayer:FeatureLayer;
private function centerMap():void
{
var point:MapPoint = new MapPoint(-118.24799,33.975004);
map.centerAt(point);
}
private function init ():void
{
sym = new PictureMarkerSymbol(widgetIcon, 30, 30);
graphicsLayer = new GraphicsLayer();
graphicsLayer.symbol =sym;
map.addLayer(graphicsLayer);
}
private function widgetClosedHandler(event:Event):void
{
graphicsLayer.visible = true;
}
private function widgetOpenedHandler(event:Event):void
{
graphicsLayer.visible = true;
}
public function getlayers():void
{
setMapAction(DrawTool.MAPPOINT, "Click Point",sym ,findsign, false);
}
private function findsign(event:DrawEvent):void
{
var geom:Geometry = event.graphic.geometry;
var pt:MapPoint = geom as MapPoint
flayer = map.getLayer("Signs") as FeatureLayer
// find wells near the mouse click
var tol:Number = map.extent.width / map.width * 5;
var x:Number = pt.x;
var y:Number = pt.y;
var queryExtent:Extent = new Extent(x - tol, y - tol, x + tol, y + tol, map.spatialReference);
var thisSelectionQuery:Query = new Query();
thisSelectionQuery.geometry = queryExtent;
flayer.selectFeatures (thisSelectionQuery, FeatureLayer.SELECTION_NEW);
flayer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE, flayer_selectionCompleteHandler)
//Alert.show ("Test")
}
private function flayer_selectionCompleteHandler(event:FeatureLayerEvent):void
{
relatedDatagrid.dataProvider = null;
//var objectID = new Number(event.features[0].attributes.ItemID);
//Alert.show(event.features[0].attributes.OBJECTID + " #event.featurelength");
// check the first return feature to see if it has any related features
if (event.features.length > 0)
{
relquery.objectIds = [ event.features[0].attributes.OBJECTID ];
//Alert.show(relquery.relationshipId + " relID");
flayer.queryRelatedFeatures(relquery, new AsyncResponder(onResult, onFault));
function onResult(relatedRecords:Object, token:Object = null):void
{
// get related records for the first feature
var fset:FeatureSet = (relatedRecords[event.features[0].attributes.OBJECTID]);
if (fset is FeatureSet)
{
relatedDatagrid.dataProvider = fset.attributes;
//Alert.show("FeatureSet Created")
}
else
{
Alert.show("No related records for ItemID: #" + event.features[0].attributes.OBJECTID, "No related records");
}
}
function onFault(info:Object, token:Object = null):void
{
map.infoWindow.hide();
Alert.show(info.toString(), "queryRelatedFeatures Problem");
}
}
else
{
map.infoWindow.hide();
Alert.show("No wells found here, please try somewhere else.", "No features");
}
}
]]>
</fx:Script>
<fx:Declarations>
<esri:RelationshipQuery id="relquery"
outFields=""
relationshipId="0" returnGeometry="true"/>
</fx:Declarations>
<viewer:WidgetTemplate id="widgetTemplate" closed="widgetClosedHandler(event)" open="widgetOpenedHandler(event)">
<mx:VBox autoLayout="false" width="200" height="200">
<mx:Button click="centerMap()" label="Recenter Map" />
<mx:Button click="activateTool()" label="Coordinates" paddingRight="25" />
<mx:Button click="getlayers()" label="GetRelatedInfo"/>
<mx:DataGrid id="relatedDatagrid" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn dataField="ItemID" headerText="ItemID"/>
<mx:DataGridColumn dataField="Condition" headerText="Condition"/>
<mx:DataGridColumn dataField="Issue" headerText="Issue"/>
<mx:DataGridColumn dataField="Assigned_To" headerText="Assigned To"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</viewer:WidgetTemplate>
</viewer:BaseWidget>