0
votes

I'm actually working on someone else code but I can't figure out something, I find the way the dataprovider is being accessed very peculiar in the mxml part.

extract 1 :

[Bindable] 
public var adrDataList:ArrayCollection = new ArrayCollection();

[Bindable]
public var obj:Object = new Object();

extract 2 :

    adrDataList.getItemAt(0).id = null;
adrDataList.getItemAt(0).natureVoie = null;
adrDataList.getItemAt(0).numeroVoie = null;
adrDataList.getItemAt(0).nomVoie = null;
adrDataList.getItemAt(0).commune = null;
adrDataList.getItemAt(0).complementAdresse = null;
adrDataList.getItemAt(0).codePostal = null;
    obj.index = i;          
    obj.statutGeocodage = _model.service.getItemAt(i).statutGeocodage;
    obj.coordX = "484646868"
    obj.coordY = "455446846"                    
    adrDataList.addItemAt(obj, 0);

this is the mxml part:

<view:CustomDataGrid id="dgAdr" height="80" width="989" allowMultipleSelection="true"
    editable="{_model.isGeocodageActif}" 
    styleName="DataGrid" dataProvider="{adrDataList}" itemEditEnd="onEditItem(event)">
    <view:columns>
        <mx:DataGridColumn headerText="NumeroVoie" dataField="numeroVoie"/>
        <mx:DataGridColumn headerText="NatureVoie" dataField="natureVoie"/>     
        <mx:DataGridColumn headerText="NomVoie" dataField="nomVoie"/>
        <mx:DataGridColumn headerText="Commune" dataField="commune"/>
        <mx:DataGridColumn headerText="CodePostal" dataField="codePostal"/>
        <mx:DataGridColumn headerText="Géocod" editable="false">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Text text="{(data.coordX == 0)? '' : data.coordX} - {(data.coordY == 0)? '' : data.coordY}" />
                </mx:Component>
            </mx:itemRenderer>          
        </mx:DataGridColumn>
        <mx:DataGridColumn headerText="Géocodage" editable="false"   dataField="statutGeocodage">
                    <mx:itemRenderer>
                        <mx:Component>
                            <formatter:geocodBtn color="{data.statutGeocodage}" horizontalAlign="center"
                                enabledBtns="{outerDocument._model.isGeocodageActif}"
                                click="outerDocument.onGeoClick(data.id, data.numeroVoie, data.natureVoie, data.nomVoie, data.commune, data.codePostal, data.idTechnicien, data.complementAdresse,event)">
                            </formatter:geocodBtn>
                        </mx:Component>
                    </mx:itemRenderer>
        </mx:DataGridColumn>        
    </view:columns>
</view:CustomDataGrid>

What I don't get is why is data.coordX is working? shouldn't it be data.obj.coordX

Thanks

Ps : I'm using flex SDK 3.5

2
What you want to research is how a Flex List component uses an ItemRenderer to display the list elements. The List uses object pooling to so that it creates only as many ItemRenderer objects as necessary to display the list elements that are currently visible. When you scroll the list, it will re-use existing item renderers rather than creating new ones. To do this, the item renderer defines a data property. So in the context of the item renderer, the current element in the data provider can be referenced by this data property.Sunil D.
Note I referred to a List component above, but the same applies to the data grid components (the grids extend List). Also, I referred to an ItemRenderer class which exists in Flex 4, in Flex 3 many compoents implement an IDataRenderer interface (there was no formal ItemRenderer class).Sunil D.
Hi, you could use ItemRenderer component [link] blogs.adobe.com/aharui/2008/08/…). But first, to solve your problem, I would a Class for example "adrObject" that will have a getter function called g_coordX, something like this:Gaston Flores
(continued here...) public function get g_coordX():Number{return internalObj.coordX;} Remember that the class adrObject will have: id, natureVoie,numeroVoie,nomVoie,commune,complementAdresse,codePostal,internalObj, And internalObj will have: index ,statutGeocodage,coordX,coordY, And adrDataList will have adrObject type objects. Finally you must use getter inside the grid: <mx:Text text="{(data.g_coordX ....I hope this helps.Gaston Flores
Sorry, if not understood, below I added a more complete example that works.Gaston Flores

2 Answers

1
votes

Class:

    package
{
    public class AdrObject
    {
         public var id:Number;
         public var natureVoie:Number;
         public var numeroVoie:Number;
         public var nomVoie:Number;
         public var commune:Number;
         public var complementAdresse:String;
         public var codePostal:String;
         public var internalObj:Object; //or may be other, such as InternalAdrObject type

        public function AdrObject()
        {
        }

        public function get g_coordX():Number{
            return internalObj.coordX;
        }
    }
}

Mxml:

    <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable] 
            [ArrayElementType("AdrObject")] 
            public var adrDataList:ArrayCollection = new ArrayCollection();
            [Bindable]
            public var obj:Object = new Object();

            public function init():void{
                var obj1:AdrObject = new AdrObject();
                var obj2:Object = new Object();
                obj1.id = null;
                obj1.natureVoie = null;
                obj1.numeroVoie = null;
                obj1.nomVoie = null;
                obj1.commune = null;
                obj1.complementAdresse = null;
                obj1.codePostal = null;
                obj2.index = 1;          
                obj2.statutGeocodage = 123;
                obj2.coordX = "484646868"
                obj2.coordY = "455446846"                    
                obj1.internalObj = obj2;
                adrDataList.addItem(obj1);
            }

        ]]>
    </mx:Script>

    <mx:DataGrid id="grid" width="100%" height="100%" dataProvider="{adrDataList}">
        <mx:columns>
            <mx:DataGridColumn dataField="g_coordX"/>       
        </mx:columns>   
    </mx:DataGrid>
</mx:Application>
0
votes

Do you mean the {data.coordX} parts? "obj" is the data that is binded to that property. Obj has it's own property "coordX" that is accessed with data.coordX

[Bindable]
public var obj:Object = new Object();

See DataBinding on Flex3 help