Select to view content in your preferred language

Filling Datagrid with FeatureSet Values.

2803
20
Jump to solution
02-21-2014 06:02 AM
EvelynHernandez
Frequent Contributor
Hey guys im trapped in this.
I want to fill a datagrid with values obtained from a featureset but i dont know how to get the parameters to put each one in the column that i want. Also the datagrid it is empty !!


Thanks for all the help.


//the Grid.  <mx:DataGrid  id="gridEquipos" x="2" y="5" width="100%" height="100%" visible="true" editable="false" dragEnabled="true" dropEnabled="true" dataProvider="{listaEquipos}" itemClick="gridEquipos_itemClickHandler(event)">                                                <mx:columns>                                                                <mx:DataGridColumn headerText="Código Equipo / Medidor" dataField="id_eq" id="IDEquipo"/>                                                                <mx:DataGridColumn headerText="Cant. Luminarias" dataField="cantLum" id="CantLuminarias"/>                                                                <mx:DataGridColumn headerText="Cant. Tramos" dataField="cantTram" id="CantTramos"/>                                                                <mx:DataGridColumn headerText="Tipo Conexión" dataField="tipoConn" id="TipoConexion"/>                                                                <mx:DataGridColumn headerText="NIS Cliente" dataField="nisClie" id="NisCliente"/>                                                                <mx:DataGridColumn headerText="??lt. Fact." dataField="observ" id="ultimaFacturacion"/>                                                </mx:columns>                                </mx:DataGrid>     //Filling grid function                 protected function gridEquipos_itemClickHandler(event:ListEvent):void                                                {                                                                   gridEquipoxTramo();                                                                var seleccionado:String = new String;                                                                seleccionado = gridEquipos.selectedItem.toString();                                                                acPolyline.removeAll();                                                                var queryTaskEquipoSelected:QueryTask = new QueryTask();                                                                queryTaskEquipoSelected.url = "http://gisred.chilquinta.cl:5555/arcgis/rest/services/AP_Municipal/AP_LA_CRUZ/MapServer/5";                                                                queryTaskEquipoSelected.useAMF = false;                                                                var queryEquipoSelected:Query = new Query();                                                                queryEquipoSelected.outFields = ["*"];                                                                queryEquipoSelected.returnGeometry = true;                                                                                                                                queryEquipoSelected.where = "ARCGIS.DBO.MEDIDORES_AP_006.id_medidor=" + seleccionado;                                                                queryEquipoSelected.spatialRelationship ="esriSpatialRelIntersects";                                                                queryEquipoSelected.outSpatialReference = myMap.spatialReference;                                                                queryTaskEquipoSelected.execute(queryEquipoSelected, new AsyncResponder(onResult, onFault));                                                                listaEquipos.removeAll();                                                                                                                                                                                                                                                function onResult(featureSet:FeatureSet, token:Object = null):void                                                                {                                                                               try{                                                                                               for each (var myGraphic:Graphic in featureSet.features)                                                                                               {                                                                                                                                                                                                                                 myGraphic.symbol=slsFind;                                                                                               //            myGraphic.symbol= infoButton;                                                                                               //            infoB=seleccionado;                                                                                                               graphicsLayer.add(myGraphic);                                                                                                                acPolyline.addItem(graphicsLayer);                                                                                                               myMap.zoomTo(featureSet.features[0].geometry);                                                                                                                                                                  myMap.level = 16;                                                                                               }                                                                                                                                                                              }catch(err:Error){                                                                                               Alert.show("no se pudo cargar el tramo");                                                                               }                                                                                                                                               }                                                                                                                                function onFault(info:Object, token:Object = null):void                                                                {                                                                                  Alert.show("id de equipo no encontrada");                                                                }                                                }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Evelyn,

   I think you gave up to soon. Setting up your development environment is going to be very important if you are going to do very much with development in Flex. The trace statement and flash debugger version are great tools for any level of development and spending time getting them ready to use is important.

As far as get a selected cell value from the AttributeTable... I dont work with the Attribute table as it is so much easier for me to setup a spark datagrid. But here is what I think based on the docs:

var at:AttributeTable = new AttributeTable();                 at.dataGrid.selectedItem

View solution in original post

0 Kudos
20 Replies
RobertScheitlin__GISP
MVP Emeritus
Evelyn,

   It should be as simple as:

function onResult(featureSet:FeatureSet, token:Object = null):void
  {
    try{
      listaEquipos = new ArrayCollection(featureSet.attributes);
      for each (var myGraphic:Graphic in featureSet.features)
      {   
        myGraphic.symbol=slsFind;
        //myGraphic.symbol= infoButton;
        //infoB=seleccionado;
        graphicsLayer.add(myGraphic); 
        acPolyline.addItem(graphicsLayer);
        myMap.zoomTo(featureSet.features[0].geometry);                                                   
        myMap.level = 16;
      }
    }catch(err:Error){
      Alert.show("no se pudo cargar el tramo");
    }
  }
0 Kudos
EvelynHernandez
Frequent Contributor
rscheitlin,

Ok i did this , how u said

protected function equiposAP_clickHandler(event:MouseEvent):void
   { 
    
    //Ver panel medidores
    TWMedidores.visible="true";
    
    var queryTaskEquipo:QueryTask = new QueryTask();
    queryTaskEquipo.url = "http://gisred.chilquinta.cl:5555/arcgis/rest/services/AP_Municipal/AP_LA_CRUZ/MapServer/5";
    queryTaskEquipo.useAMF = false;
    var queryEquipo:Query = new Query();
    queryEquipo.outFields = ["*"];
    queryEquipo.returnGeometry = false;
    queryEquipo.where = "1=1";
    queryTaskEquipo.execute(queryEquipo, new AsyncResponder(onResult, onFault));
    
     function onResult(featureSet:FeatureSet, token:Object = null):void
    { 
     
     listaEquipos = new ArrayCollection(featureSet.attributes);
     
     
    }
    function onFault(info:Object, token:Object = null):void
    {
     Alert.show("no se puede cargar equipo "+ info.toString());
    }
    gridEquipos.dataProvider(listaEquipos); 
   }


But i still dont know if it is correct in the grid call the fields like this.
In the map server , the fields have those names, but i dont know if the arrayCollection will keep those names or i have to rename them.
I did that and my grid still doesnt work.. it doesnt show anything 😞
Thanks for ur help.

<mx:DataGrid  id="gridEquipos" x="2" y="5" width="100%" height="100%" visible="true" editable="false" dragEnabled="true" dropEnabled="true" itemClick="gridEquipos_itemClickHandler(event)" dataProvider="{listaEquipos}">
   <mx:columns>
    <mx:DataGridColumn headerText="Código Equipo / Medidor" dataField="ARCGIS.DBO.MEDIDORES_AP_006.id_medidor" id="id_equipo"/>
    <mx:DataGridColumn headerText="Tipo Conex." dataField="ARCGIS.DBO.MEDIDORES_AP_006.tipo_conexion" id="tipo_conex"/>
    <mx:DataGridColumn headerText="Cant. Tramos" dataField="ARCGIS.DBO.MEDIDORES_AP_006.tramos_ap" id="cant_tramos"/>
    <mx:DataGridColumn headerText="Nro. NIS" dataField="ARCGIS.DBO.MEDIDORES_AP_006.nis" id="nro_nis"/>
    <mx:DataGridColumn headerText="Cant. Luminarias" dataField="ARCGIS.DBO.MEDIDORES_AP_006.luminarias" id="cant_luminarias"/>
   </mx:columns>
  </mx:DataGrid>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Evelyn,

   Here is a working sample. You will see that your issue is likely that you are trying to assign the datagrids data provider in your equipoAP_clickHandler. This is an issue because the results of the query are not completed before it gets to that line of code and actually that line is not needed at all as you have already defined the dataProvider in the datagrid attributes.

<?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">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import com.esri.ags.FeatureSet;
            import com.esri.ags.tasks.QueryTask;
            import com.esri.ags.tasks.supportClasses.Query;
            
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.ListEvent;
            import mx.rpc.AsyncResponder;
            
            [Bindable]
            private var listaEquipos:ArrayCollection;
            
            protected function equiposAP_clickHandler(event:MouseEvent):void
            {    
                var queryTaskEquipo:QueryTask = new QueryTask();
                queryTaskEquipo.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer/2";
                queryTaskEquipo.useAMF = false;
                var queryEquipo:Query = new Query();
                queryEquipo.outFields = ["*"];
                queryEquipo.returnGeometry = false;
                queryEquipo.where = "1=1";
                queryTaskEquipo.execute(queryEquipo, new AsyncResponder(onResult, onFault));
                
                function onResult(featureSet:FeatureSet, token:Object = null):void
                { 
                    listaEquipos = new ArrayCollection(featureSet.attributes); 
                }
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show("no se puede cargar equipo "+ info.toString());
                }
                //No need for this
                //gridEquipos.dataProvider(listaEquipos); 
            }
            
            protected function gridEquipos_itemClickHandler(event:ListEvent):void
            {
                // TODO Auto-generated method stub
                
            }
            
        ]]>
    </fx:Script>
    <s:controlBarLayout>
        <s:VerticalLayout gap="10"
                          paddingBottom="7"
                          paddingLeft="10"
                          paddingRight="10"
                          paddingTop="7"/>
    </s:controlBarLayout>
    <s:controlBarContent>
        <s:RichText width="100%">
            This sample demonstrates how to populate a datagrid with the results of a querytask
        </s:RichText>
        <s:Button id="popButton"
                  click="equiposAP_clickHandler(event)"
                  label="execute query..."/>
    </s:controlBarContent>
    <mx:DataGrid  id="gridEquipos" width="100%" height="100%" visible="true" editable="false" dragEnabled="true" dropEnabled="true" itemClick="gridEquipos_itemClickHandler(event)" dataProvider="{listaEquipos}">
        <mx:columns>
            <mx:DataGridColumn headerText="Código Equipo / Medidor" dataField="OBJECTID" id="id_equipo"/>
            <mx:DataGridColumn headerText="Tipo Conex." dataField="ZONING_CODE" id="tipo_conex"/>
            <mx:DataGridColumn headerText="Cant. Tramos" dataField="ZONING_NAME" id="cant_tramos"/>
            <mx:DataGridColumn headerText="Nro. NIS" dataField="ZONING_TYPE" id="nro_nis"/>
        </mx:columns>
    </mx:DataGrid>
</s:Application>
0 Kudos
EvelynHernandez
Frequent Contributor
rscheitlin,

Yeah, you example works perfectly.
I tried to change my map and parameters into ur example but i receive an error trying to make a query

RPC Fault faultString="Token Required" faultCode="499" faultDetail=""]

The map query is http://gisred.chilquinta.cl:5555/arcgis/rest/services/AP_Municipal/AP_LA_CRUZ/MapServer/5
and some of the values that i want to obtain are
ARCGIS.DBO.MEDIDORES_AP_006.id_medidor ( type: esriFieldTypeString , alias: id , length: 50 )
ARCGIS.DBO.MEDIDORES_AP_006.propiedad ( type: esriFieldTypeString , alias: propiedad , length: 99 )

i dont know what is happening 😞
Thanks for ur patience ! !
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Evelyn,

   That makes sense as your map service you are trying to use is secured. You will have to obtain a token and add that token to the queryTask.
0 Kudos
EvelynHernandez
Frequent Contributor
rscheitlin,

I did that already putting the token in the code.
The onResult add the features.attributes on the arraycollection, but the grid still doesnt show anything 😞
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Evelyn,

  Are you still getting that same error RPC Fault faultString="Token Required" faultCode="499" faultDetail=""]?
0 Kudos
EvelynHernandez
Frequent Contributor
No.
In the onresult i put this alert to see if the query is going to pass through other side, but it shows the alert "did it", so i assume that the AC has the data given from the featureset.

Maybe it is something wrong with the datagrid.

I have this on my dgrid.

<mx:DataGrid  id="gridEquipos" width="30%" height="30%" visible="true" editable="false" dragEnabled="true" dropEnabled="true" itemClick="gridEquipos_itemClickHandler(event)" dataProvider="{listaEquipos}">
   <mx:columns>
    <mx:DataGridColumn headerText="Código Equipo / Medidor" dataField="ARCGIS.DBO.MEDIDORES_AP_006.id_medidor"/>
    
   </mx:columns>
  </mx:DataGrid>


and this is the onresult function.

function onResult(featureSet:FeatureSet, token:Object = null):void
    { 
     listaEquipos = new ArrayCollection(featureSet.attributes);
     Alert.show("did it");
     
    }



Thanks for ur patience !
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Evelyn,

   Are you sure your field names need to be fully qualified like you have them?

dataField="ARCGIS.DBO.MEDIDORES_AP_006.id_medidor"

maybe try

dataField="id_medidor"

again.
0 Kudos