Select to view content in your preferred language

Higlight related records in the attribute table

2298
4
01-31-2014 05:13 AM
ionarawilson1
Deactivated User
My application has a map and an attribute table. The map shows offices and the table shows office activities related to those offices. When I click on the office, I would like the related records on the attribute table. I created a related query And I am able to get the number of related records but I haven't been able to highlight the records in the table. Can you guys offer any help? Thank you!!!

[Bindable]private var selectedObjectID:Number;
[Bindable]private var relatedRecordsCount:Number;
 
private function wellsLayer_selectionCompleteHandler(event:FeatureLayerEvent):void
{
    
// 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;
 myFeatureLayer.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)
 {
     
  relatedRecordsCount = fset.attributes.length;
  numberofrelatedrecords.text = relatedRecordsCount.toString()
   }
 else
 {
 Alert.show("No related records for record #" + event.features[0].attributes.OBJECTID, "No related records");
     
   }
   }
 function onFault(info:Object, token:Object = null):void
   {
    myMap.infoWindow.hide();
    Alert.show(info.toString(), "queryRelatedFeatures Problem");
   }
  }
   else
   {
    myMap.infoWindow.hide();
    Alert.show("No wells found here, please try somewhere else.", "No features");
    }
   }
<fx:Declarations>
  <esri:RelationshipQuery id="relatedTopsQuery"
  outFields=""

  relationshipId="0"/>
  <esri:RelationshipInspector id="relationshipInspector"
  width="590" height="400"
  editEnabled="true"/>
  <esri:FeatureLayer id="yourTable"    fault="fLayer_faultHandler(event)"
    loadError="fLayer_loadErrorHandler(event)"
     mode="snapshot"
     updateEnd="fLayer_updateEndHandler(event)"
     updateStart="fLayer_updateStartHandler(event)" outFields="*"      disableClientCaching="true"
  url="http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES_ALL/FeatureServer/8"/>  
 </fx:Declarations>
 <layers:MyFeatureLayer mode="onDemand"        selectionComplete="wellsLayer_selectionCompleteHandler(event)" id="myFeatureLayer" visible="false"     graphicAdd="onGraphicAdd(event)"  updateEnd="onLayerUpdateEnd(event)"  outFields="*" url="http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES_ALL/FeatureServer/0"/>    

<esri:AttributeTable 
id="myAttributeTable"
width="100%"  
visible="false"
deleteFeatures="fdg_deleteFeaturesHandler(event)"
showTitle="false"
featureLayer="{yourTable}"
updateFeature="fdg_updateFeatureHandler(event)">   
<esri:FieldInspector editor="com.esri.ags.samples.components.MyCalendarEditor"
 fieldName="DateComplete"/>
</esri:AttributeTable>       
Tags (2)
0 Kudos
4 Replies
AndreasRuloffs1
Occasional Contributor
Hello,
I have never worked with an AttributeTable, so everything I write is to be taken carefully.
The AttributeTable is bound to the selection of the related FeatureLayer.
So you would need a function like myFeatureLayer.selectRelatedFeatures which unfortunately does not exists.
I would perform a selectFeatures on the FeatureLayer yourTable.
This could be done in the onResult handler and should select all the features from within the resultSet.

Bye,
Andreas Ruloffs
0 Kudos
ionarawilson1
Deactivated User
Thank you Andreas. I created query with a definition expression. It does not highlight the records as I don't know if there is a way to do that with an attribute table but it filters the table. I've tried a new selection but that did not work.

         function onResult(relatedRecords:Object, token:Object = null):void
             { 
              
              var defexpr:String = ""
              // get related records for the first feature
              var fset:FeatureSet = (relatedRecords[event.features[0].attributes.OBJECTID]);
              if (fset is FeatureSet)
              {
          
               relatedRecordsCount = fset.attributes.length;
               numberofrelatedrecords.text = relatedRecordsCount.toString()
               for (var i=0, il=fset.attributes.length; i<il; i++)
               {
                  //var objectidstring:String = String(fset.attributes.OBJECTID)
                   //Alert.show(objectidstring)
                
                if (i == 0)
                {
                 defexpr = "OBJECTID" + " =" + fset.attributes.OBJECTID
                }
                else
                {
                 defexpr = defexpr + " or " + "OBJECTID" + " = " + fset.attributes.OBJECTID
                }
               
               }

               yourTable.definitionExpression = defexpr
               Alert.show(defexpr)
               query.where = defexpr;
               query.objectIds=[];
               query.returnGeometry = false;
               queryTask.executeForIds(query);
               
               myAttributeTable.featureLayer = myFeatureLayer  
               myAttributeTable.featureLayer = yourTable
               myAttributeTable.visible = true;
               
               yourTable.visible = true

               myAttributeTable.featureLayer = yourTable
              
             
                
              }

    

0 Kudos
AndreasRuloffs1
Occasional Contributor
Hello,
try to replace
[PHP]
yourTable.definitionExpression = defexpr
               Alert.show(defexpr)
               query.where = defexpr;
               query.objectIds=[];
               query.returnGeometry = false;
               queryTask.executeForIds(query);
              
               myAttributeTable.featureLayer = myFeatureLayer 
               myAttributeTable.featureLayer = yourTable
               myAttributeTable.visible = true;
              
               yourTable.visible = true

               myAttributeTable.featureLayer = yourTable[/PHP]

with:
[PHP]
   var selectionQuery:Query = new Query();
   selectionQuery.where = defexpr;
   myAttributeTable.featureLayer.selectFeatures(selectionQuery);
[/PHP]
0 Kudos
ionarawilson1
Deactivated User
Unfortunately it does not work Andreas, but thanks for trying to help. I will just keep the definition expression for now to filter out the results, but it would be nice to know how to highlight features in an attribute table one day.
0 Kudos