Skip navigation
Currently Being Moderated

Change the order of Flex Object's Property names

May 1, 2012 4:29 AM

Tags: #order #object #name #property

Hi Folks,

Is there anyways to change the order of Flex Object's Property names?

For example,

var obj:Object = {id:121,name:some name,address:some address}

I have added this object into arraycollection and set that arraycollection as a dataprovider to datagrid. But the columns in the datagrid are not in the order(id,name,address), which I gave in the object. Instead it shows theproperty names in alphabatical order (address,id,name).

 

Any help much appreciated.

 

Thanks in advance.

 

With Regards,

 

Arun Ganesh. P

 
Replies
  • Currently Being Moderated
    May 1, 2012 5:47 AM   in reply to Arun Ganesh

    here is a solution using flex 4.6

     

     

    <?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" minWidth="955" minHeight="600"
                                                                                     applicationComplete="init()">
              <fx:Declarations>
                        <!-- Place non-visual elements (e.g., services, value objects) here -->
              </fx:Declarations>
              
                          <fx:Script>
                                    <![CDATA[
                                            import mx.collections.ArrayList;
      
                                            [Bindable]
                                            private var arrayList:ArrayList = new ArrayList();
      
                                            private function init():void
                                            {
                                                      for (var i:int = 0; i < 10; i++)
                                                      {
                                                                var obj:Object = { id: i, name:"name"+i, address:"address"+i };
                                                                arrayList.addItem(obj);
                                                      }
                                            }
                                    ]]>
                          </fx:Script>
                          
                          <s:DataGrid dataProvider="{arrayList}">
                                    <s:columns>
                                               <s:ArrayList>
                            <s:GridColumn dataField="id" width="50" />
                            <s:GridColumn dataField="name" width="100" />
                                                                <s:GridColumn dataField="address" width="200"/>
                        </s:ArrayList>
                                    </s:columns>
                          </s:DataGrid>
    </s:Application>
    
    
     
    |
    Mark as:
  • Currently Being Moderated
    May 1, 2012 6:01 AM   in reply to Arun Ganesh

    as far as I am aware this is the only way to control the order, if you need to do it dynamically you will need to dynamically create the columns yourself

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points