4 Replies Latest reply on May 1, 2012 6:06 AM by Arun Ganesh

    Change the order of Flex Object's Property names

    Arun Ganesh Level 3

      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

        • 1. Re: Change the order of Flex Object's Property names
          _spoboyle Level 4

          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>
          
          
          • 2. Re: Change the order of Flex Object's Property names
            Arun Ganesh Level 3

            Thanks for your response.

            Actualy I am not going to manualy assign the columns to datagrid. It will automatically create the columns according to the dataprovider's fields.

            • 3. Re: Change the order of Flex Object's Property names
              _spoboyle Level 4

              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

              • 4. Re: Change the order of Flex Object's Property names
                Arun Ganesh Level 3

                Actualy I use this datagrid for report purpose. Report may vary according to user's selection(columns too). Datagrid has the ability to create columns according to the dataprovider. But the problem is, it arranges the columns in alphabatical order.