Edit related records?

3465
15
Jump to solution
12-06-2013 11:18 AM
ionarawilson1
Occasional Contributor III
I need to be able to edit records in a standalone table, so I want to use related records. I am trying to combine the related records sample with the edit attributes sample. However from what I understand I need to use a link to a featureServer to be able to edit records and the example with the related records uses a link to a mapServer. Is it possible to combine both samples to be able to edit records in the related table or is there a better way to edit related records? Thank you for any help!!!

Here are the links to the samples

https://developers.arcgis.com/en/flex/sample-code/attributetable.htm

https://developers.arcgis.com/en/flex/sample-code/related-records.htm
Tags (2)
0 Kudos
15 Replies
BenjaminMercier
New Contributor III
Hi,

It's due to the component Attribute Table. It's just selectingin the table the entities answered to the query among all the entities.

If you want to do that, you could develop your own 'attribute table' displaying your data in a flex datagrid. Here is a quick example : https://developers.arcgis.com/en/flex/sample-code/query-result-in-table.htm. But it's highly customizable.
0 Kudos
ionarawilson1
Occasional Contributor III
How can I make it select the record(s)? It is not selecting anything on the table.

I thought about using that example but the problem is that the dataprovider of the data grid is an array with the results of the query and the query is done in a map service and I need to have the attribute table with data linked to a feature layer so I can edit the records. Is it possible to run a query  or a definition query on the feature layer (the table)?
0 Kudos
BenjaminMercier
New Contributor III
As I remembered it worked on my layer...

For the datagrid, you could keep the same idea to populate it. Then a datagrid is a flex component which could be editable. If you put it as editable, the dataprovider (so an arrayCollection) will be modified.

For instance, you could add a "Save" button which launch an applyEdits on your featureLayer. You have to convert each lines of the datagrid in an object like "attributes", then push it in an array. Thus you'll use applyEdits like on every other example you could find here.

I'm away for 2 days, but if you want I could give you an example. Perhaps try to populate your DG and make this "Save" button. Send me the code, I'll see that in 2 days.

Good luck

Ben,
0 Kudos
ionarawilson1
Occasional Contributor III
Benjamin, can you please send me an example and I will start to work on it! Thank you so much!
0 Kudos
ionarawilson1
Occasional Contributor III
Ben,

I think I got it, but I would like to know how to the editing in the datagrid so if you can please send me an example, it would be good because I found this way filters the data in the attribute table but it does not let me edit it. Would you happen to know why? It appears that it is not adding it as a feature layer, just as a table although I am casting it as a feature layer. Thanks

Here is how I did:

 <s:TextInput id="qText"
       width="100%"
       enter="doSearch()"
       text="AU"
       toolTip="You may use % as a wildcard, e.g., A%"/>
   <s:Button click="doSearch()" label="Search"/>



and I create the feature when I click the search button and also set the feature layer of the attribute layer

 {
   
   
     var urltable:String = "http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES/FeatureServer/1" //or you can use your feature layer layerDetails informations to get the related table Id.
     var yourTable:FeatureLayer; //Here you're casting the table as a FeatureLayer so it's editable
    yourTable = new FeatureLayer(urltable, null, null) as FeatureLayer;
    yourTable.outFields = ["*"];
    yourTable.definitionExpression = "Office like '" + qText.text + "'";
    myAttributeTable.featureLayer = yourTable
   }
0 Kudos
ionarawilson1
Occasional Contributor III
Hi Ben,

Here is the example with related records and an editable datagrid. Do you think you can help me with the  save and delete functions? Thank you so much for all your help!

<?xml version="1.0" encoding="utf-8"?>
<s:Application 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:esri="http://www.esri.com/2008/ags"
      pageTitle="Related records">
 
 
 <s:layout>
  <s:VerticalLayout gap="0"/>
 </s:layout>
 
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.events.FeatureLayerEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.Extent;
   import com.esri.ags.tasks.supportClasses.Query;
   import com.esri.ags.tasks.supportClasses.RelationshipQuery;
   
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   
   [Bindable]
   private var selectedObjectID:Number;
   [Bindable]
   private var relatedRecordsCount:Number;
   
   
   
   private function findWells(event:MapMouseEvent):void
   {
    // find wells near the mouse click
    var tol:Number = map.extent.width / map.width * 5;
    var x:Number = event.mapPoint.x;
    var y:Number = event.mapPoint.y;
    var queryExtent:Extent = new Extent(x - tol, y - tol, x + tol, y + tol, event.mapPoint.spatialReference);
    var thisSelectionQuery:Query = new Query();
    thisSelectionQuery.geometry = queryExtent;
    wellsLayer.selectFeatures(thisSelectionQuery, FeatureLayer.SELECTION_NEW);
   }
   
   private function wellsLayer_selectionCompleteHandler(event:FeatureLayerEvent):void
   {
    relatedDatagrid.dataProvider = null;
    // check the first return feature to see if it has any related features
    if (event.features.length > 0)
    {
     relatedTopsQuery.objectIds = [ event.features[0].attributes.OBJECTID ];
     selectedObjectID = event.features[0].attributes.OBJECTID;
     wellsLayer.queryRelatedFeatures(relatedTopsQuery, 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 = new ArrayCollection(fset.attributes)
       relatedRecordsCount = fset.attributes.length;
      }
      else
      {
       Alert.show("No related records for well #" + event.features[0].attributes.OBJECTID, "No related records");
       relatedRecordsCount = 0;
      }
     }
     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");
    }
   }
   
   protected function saveRelatedRecordsForObjectID(event:MouseEvent):void
   {
    
   }
   
   protected function deleteRelatedRecordsForObjectID(event:MouseEvent):void
   {
    
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:RelationshipQuery id="relatedTopsQuery"
        outFields="[OBJECTID,API_NUMBER,ELEVATION,FORMATION,TOP]"
        relationshipId="3"/>
 </fx:Declarations>
 
 <s:controlBarLayout>
  <s:VerticalLayout gap="10"
        paddingBottom="7"
        paddingLeft="10"
        paddingRight="10"
        paddingTop="7"/>
 </s:controlBarLayout>
 <s:controlBarContent>
 
  <s:Button click="saveRelatedRecordsForObjectID(event)"
      label="Save"
      visible="{relatedRecordsCount > 0}"/>
  
  <s:Button
   click="deleteRelatedRecordsForObjectID(event)"
   label= "Delete Records"
   visible="{relatedRecordsCount > 0}"/>
  
 </s:controlBarContent>
 
 <esri:Map id="map" mapClick="findWells(event)">
  <esri:extent>
   <esri:Extent xmin="-10854000" ymin="4502000" xmax="-10829000" ymax="4524000">
    <esri:SpatialReference wkid="102100"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
  <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer">
   <esri:visibleLayers>
    <s:ArrayCollection>
     <fx:Number>0</fx:Number>
     <fx:Number>1</fx:Number>
    </s:ArrayCollection>
   </esri:visibleLayers>
  </esri:ArcGISDynamicMapServiceLayer>
  <esri:FeatureLayer id="wellsLayer"
         mode="selection"
         outFields="[completion,plug_date]"
         selectionComplete="wellsLayer_selectionCompleteHandler(event)"
         url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0">
   <esri:infoWindowRenderer>
    <fx:Component>
     <esri:LabelDataRenderer>
      <esri:layout>
       <s:VerticalLayout/>
      </esri:layout>
      <esri:label>Well ID {data.OBJECTID}</esri:label>
      <s:Label text="Plug date: {data.plug_date ? new Date(data.plug_date) : 'No date available'}"/>
      <s:Label text="Completion: {data.completion ? new Date(data.completion) : 'No date available'}"/>
     </esri:LabelDataRenderer>
    </fx:Component>
   </esri:infoWindowRenderer>
  </esri:FeatureLayer>
 </esri:Map>
 <s:DataGrid id="relatedDatagrid"
    width="100%" height="45%">
  <s:columns>
   <s:ArrayList>
    <s:GridColumn dataField="OBJECTID" headerText="ID"/>
    <s:GridColumn dataField="API_NUMBER" headerText="API Number"/>
    <s:GridColumn dataField="ELEVATION" headerText="Elevation"/>
    <s:GridColumn dataField="FORMATION" headerText="Formation"/>
    <s:GridColumn dataField="TOP" headerText="Top"/>
   </s:ArrayList>
  </s:columns>
 </s:DataGrid>
 
</s:Application>


0 Kudos