2 Replies Latest reply on Sep 1, 2010 4:27 AM by IlyaG

    Looking for DataGrid sample

    IlyaG Level 1

      Hi,

       

      I have a function that gives me two arrays and I want to show them on data grid, those are my arrays:

       

      var names:Array;

      var LastNames:Array;

       

      And all what I want is to create a 3 columns datagrid with names, lastNames and full names.

       

      Can you help me with this one?

        • 1. Re: Looking for DataGrid sample
          ShardulSingh Level 3

          Hi,

          Pls find the solution for ur problem. Let me know if you have any issue.

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      private var arrNames : Array = ['aName','bName','cName'];
                      private var arrLastNames : Array = ['aLastName','bLastName','cLastName'];
                     
                      [Bindable]
                      private var arrCollection : ArrayCollection = new ArrayCollection();
                     
                      private function createColl() : void
                      {
                          for (var i : Number= 0; i< arrNames.length; i++)
                          {   
                              var obj : Object = new Object();
                              obj.firstName = arrNames[i];
                              obj.lastName =  arrLastNames[i];
                              obj.fullName = obj.firstName + "  " + obj.lastName;
                              arrCollection.addItem(obj);
                          }
                      }
                     
                     
                  ]]>
              </mx:Script>
              <mx:DataGrid dataProvider="{arrCollection}" creationComplete="createColl()">
              <mx:columns>
                  <mx:DataGridColumn width="150" dataField="firstName" headerText="First Name"/>
                  <mx:DataGridColumn width="150" dataField="lastName" headerText="Last Name"/>
                  <mx:DataGridColumn width="250" dataField="fullName" headerText="Full Name"/>
              </mx:columns>
              </mx:DataGrid>
          </mx:Application>

           

           

           

           

           

           

          with Regards,

           

          Shradul Singh Bartwal

          • 2. Re: Looking for DataGrid sample
            IlyaG Level 1

            Tnx, this is what I been looking for.