3 Replies Latest reply on Nov 25, 2009 8:11 AM by Subeesh Arakkan

    Removing a Column from an ArrayCollection

    MrFork

      Hello All,

       

      As the subject header states, how does one remove a whole column from an array. So for example I have this scenario;

       

      var removeColumn:String = 'value';

       

      var myData:ArrayCollection =

      {month:"Jan", value:2000}

      {month:"Jan", value:2000}

      {month:"Jan", value:2000}

       

      delete removeColumn from myData

       

      So therefore the array is just:

       

      {month:"Jan"}

      {month:"Jan"}

      {month:"Jan"}

       

      Anyone have any ideas / workarounds?

        • 1. Re: Removing a Column from an ArrayCollection
          Subeesh Arakkan Level 4

          Hi,

           

          I am not sure if this is the best approach but the following function will work for you

                         private function removeColumn(coll:ArrayCollection, columnName:String):ArrayCollection
                         {
                              var newColl:ArrayCollection=new ArrayCollection();
                              for each (var item:Object in coll)
                              {
                                   var obj:Object=new Object();
                                   for (var column:String in item)
                                   {
                                        if (column != columnName)
                                             obj[column]=item[column];
                                   }
                                   newColl.addItem(obj);
                              }
                              return newColl;
                         }
          
          • 2. Re: Removing a Column from an ArrayCollection
            Gregor K

            He'd probably get better traction with

             

                           private function removeColumn(coll:ArrayCollection,

            columnName:String) : void

                           {

                                for each (var item:Object in coll)

                                {

                                     delete item[columnName];

                                }

                           }

            • 3. Re: Removing a Column from an ArrayCollection
              Subeesh Arakkan Level 4

              Yes, that is the better option