Why is feature layer not editable when is programatic?

999
6
Jump to solution
12-12-2013 04:18 AM
ionarawilson1
Occasional Contributor III
I am binding an attribute table to a feature layer that is actually a standalone table published as a feature service. When I add the feature layer in the declarations, the feature layer is editable but when I add it programmatically, although I cast it as a feature layer is not recognized as a feature layer and it is not editable. Do you guys know why this occurs and how to make it editable when I add it programaticaly? Thanks

Here is the feature layer when added declaratively:

 <fx:Declarations>   <esri:RelationshipInspector id="relationshipInspector"          width="590" height="400"                    editEnabled="true"/>   <esri:FeatureLayer id="yourTable"    fault="fLayer_faultHandler(event)"          load="{doSearch()}"                    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/FeatureServer/1"/>        </fx:Declarations>               <esri:AttributeTable     id="myAttributeTable"    width="100%" height="55%"    deleteFeatures="fdg_deleteFeaturesHandler(event)"    featureLayer="{yourTable}"        updateFeature="fdg_updateFeatureHandler(event)">               </esri:AttributeTable>      


And here it is programatically:

private function doSearch():void    {             // 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     var yourTable:com.esri.ags.layers.FeatureLayer = new com.esri.ags.layers.FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES/FeatureServer/1") as com.esri.ags.layers.FeatureLayer;                  //  yourTable = new FeatureLayer(urltable, null, null) as FeatureLayer;     yourTable.enabled = true;     yourTable.outFields = ['*'];     yourTable.mode = "onDemand"     yourTable.useAMF = true;         yourTable.definitionExpression = "Office like '" + qText.text + "'";     myAttributeTable.featureLayer = yourTable as FeatureLayer     yourTable.visible = true     yourTable.isEditable = true;           if (yourTable is FeatureLayer)     {        Alert.show("TEST")     }    }    <esri:AttributeTable     id="myAttributeTable"    width="100%" height="55%"    deleteFeatures="fdg_deleteFeaturesHandler(event)"       updateFeature="fdg_updateFeatureHandler(event)">               </esri:AttributeTable>      
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Occasional Contributor III
I did it! I am able to filter the feature layer now in the attribute table. It is a sloppy way, but it works. When I select the point now, I set first the feature layer to any other feature layer, in this case the layer that is displayed on the map, then I set a definition expression, then I set the feature layer of the attribute table to the feature layer I want (the stand alone table). Thank you so much for your help again! Without you, I could not have got this far in my web app and in my continuous learning process.


 protected function myFeatureLayer_SelectionCompleteHandler(event:FeatureLayerEvent):void    {     var query2:Query = new Query;     ///query.where =  "Office like '" + qText.text + "'";     query2.where = "Office like '"  + myFeatureLayer.selectedFeatures[0].attributes.NAME_SH  + "'";     myAttributeTable.featureLayer = myFeatureLayer     //yourTable.selectFeatures(query2, FeatureLayer.SELECTION_NEW);             yourTable.definitionExpression = "Office like '"  + myFeatureLayer.selectedFeatures[0].attributes.NAME_SH  + "'";       myAttributeTable.featureLayer = yourTable    }    

View solution in original post

0 Kudos
6 Replies
BenjaminMercier
New Contributor III
I don't really know what you want to do then, but the variable yourTable is created inside a function, so it's not visible outside.

To put the featureLayer in <Declarations> as same effect for the varaible a declared it in global variable.

Why not let it between <Declarations> ? It's actually made for that, declaring data which are not aimed to be displayed as an UI component.

Ben
0 Kudos
ionarawilson1
Occasional Contributor III
What I need is to have a table that I can edit but also do a filter search. With the example you gave me, the one that uses the declarative way of adding the table as a feature layer is perfect but I can only filter if I create the feature layer in the search function, but I lose the ability of editing. That's why I was experimenting with other samples, that use a datagrid like the related records example, that already has a search function on the table, but it is not easy to make it editable. Is there a  way to filter that attribute table in the first example you gave me? Thanks
0 Kudos
BenjaminMercier
New Contributor III
I don't really know, I'm not able to customize the attributeTable component, but I guess that it will be as difficult as making your own table with datagrid
0 Kudos
ionarawilson1
Occasional Contributor III
Yes, I agree with you. I was able to make the selection work on the attribute table when I select the point on the map. Upon selecting a point, all related records are selected in the attribute table, but it would be nice if I could filter it and only have those records. That's why I did a definition query in a search function, but then I have to create the feature layer inside the function and the editing does not work. Here is my selection code:

   protected function myMap_clickHandler(event:MapMouseEvent):void
   {
    
    mapClickPoint = event.mapPoint;
    if (event.originalTarget is Graphic || event.originalTarget.parent is Graphic)               
    {                    
     var graphic:Graphic = event.originalTarget is Graphic ? Graphic(event.originalTarget) : Graphic(event.originalTarget.parent);
     var query:Query = new Query;
     query.objectIds = [graphic.attributes[myFeatureLayer.layerDetails.objectIdField]];
     myFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
     myFeatureLayer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE,myFeatureLayer_SelectionCompleteHandler);
     
     
    }
    else
     {
        myFeatureLayer.clearSelection();
        yourTable.clearSelection();
     }
  
    if (event.originalTarget is Graphic || event.originalTarget.parent is Graphic) // for PictureMarkerSymbol target is not graphic(graphic contains a child object)
    {
     if (event.originalTarget is Graphic)
     {
      selectedGraphic = Graphic(event.originalTarget);
     }
     else if (event.originalTarget.parent is Graphic) //check for PictureMarkerSymbol
     {
      selectedGraphic = Graphic(event.originalTarget.parent);
     }
     myMap.infoWindow.content = relationshipInspector;
     relationshipInspector.infoWindowLabel = "Office: " + selectedGraphic.attributes["NAME"];
     relationshipInspector.graphic = selectedGraphic;
     myMap.infoWindow.show(mapClickPoint);
    }
    else
    {
     myMap.infoWindow.hide();
     Alert.show("No incidents found here, please try somewhere else.", "No features");
    }
//    else
//    {
//     myFeatureLayer.clearSelection();
//     yourTable.clearSelection();
//    }
   }
   
   protected function myFeatureLayer_SelectionCompleteHandler(event:FeatureLayerEvent):void
   {
    var query2:Query = new Query;
    ///query.where =  "Office like '" + qText.text + "'";
    query2.where = "Office like '"  + myFeatureLayer.selectedFeatures[0].attributes.NAME_SH  + "'";
    yourTable.selectFeatures(query2, FeatureLayer.SELECTION_NEW);
       
    
    
   }
0 Kudos
ionarawilson1
Occasional Contributor III
I also got a filter function that works on feature layers but I just got the graphics in the map to be filtered. If I could grab the item attributes of the table I could filter it also. Here is the function and the class created for it

 import com.esri.ags.Graphic;
   import com.esri.ags.events.GraphicEvent;
   import com.esri.ags.events.LayerEvent;
   
   import mx.collections.ArrayCollection;
   
   [Bindable]
   private var totalGraphicsShown:String = "";
   
   private var filterParam:String;
   
   protected function onFilterClick(event:MouseEvent):void
   {
    var bt:Button = Button(event.target);
    switch (bt.id)
    {
     case bt100.id:
      filterParam = "AL";
      break;
     case bt300.id:
      filterParam = "AU";
      break;
     case bt500.id:
      filterParam = "BE";
      break;
     case bt700.id:
      filterParam = "CY";
      break;
     case bt900.id:
      filterParam = "CA";
      break;
    }
    
    myFeatureLayer.setFilterFunction(providerFilterFunction);
   }
   
   protected function onClearFilters(event:MouseEvent):void
   {
    myFeatureLayer.setFilterFunction(null);
   }
   
   protected function providerFilterFunction(item:Object):Boolean
   {
    var isFiltered:Boolean = false;
    var gr:Graphic = Graphic(item);
    if (gr.attributes.NAME_SH == filterParam)
    {
     isFiltered = true;
    }
    return isFiltered;
   }


package MyFeatureLayer
{
 import com.esri.ags.layers.FeatureLayer;
 
 import com.esri.ags.events.LayerEvent;
 import com.esri.ags.layers.FeatureLayer;
 
 public class MyFeatureLayer extends FeatureLayer
 {
  public function MyFeatureLayer(url:String=null, proxyURL:String=null, token:String=null)
  {
   super(url, proxyURL, token);
  }
  
  public function setFilterFunction(func:Function):void
  {
   $graphicProvider.filterFunction = func;
   $graphicProvider.refresh();
   dispatchEvent(new LayerEvent(LayerEvent.UPDATE_END, this, null, true));
  }
 }
}
0 Kudos
ionarawilson1
Occasional Contributor III
I did it! I am able to filter the feature layer now in the attribute table. It is a sloppy way, but it works. When I select the point now, I set first the feature layer to any other feature layer, in this case the layer that is displayed on the map, then I set a definition expression, then I set the feature layer of the attribute table to the feature layer I want (the stand alone table). Thank you so much for your help again! Without you, I could not have got this far in my web app and in my continuous learning process.


 protected function myFeatureLayer_SelectionCompleteHandler(event:FeatureLayerEvent):void    {     var query2:Query = new Query;     ///query.where =  "Office like '" + qText.text + "'";     query2.where = "Office like '"  + myFeatureLayer.selectedFeatures[0].attributes.NAME_SH  + "'";     myAttributeTable.featureLayer = myFeatureLayer     //yourTable.selectFeatures(query2, FeatureLayer.SELECTION_NEW);             yourTable.definitionExpression = "Office like '"  + myFeatureLayer.selectedFeatures[0].attributes.NAME_SH  + "'";       myAttributeTable.featureLayer = yourTable    }    
0 Kudos