2 Replies Latest reply on Jan 4, 2010 11:28 AM by Handycam

    Allow user-created data in empty datagrid?

    Handycam Level 1

      I have an app where I was considering having a datagrid where users would enter information, and then total up what they entered.

       

      So I have an empty datagrid such as

       

      http://grab.by/1wRQ

       

      I would like a user to be able to enter (for example) 2 units (qty) at 100 width and 200 height in the first row.  Ultimately, I will add a button that provides the math, which in this case would be 2 X (100X200) and then totals each row.

       

      I have never worked with an empty grid before; so I created a new arrayCollection and have bound it to the dataprovider for the grid.  Apparently there is more to it than simply that, as I can't edit the grid to add data (columns and grid editable=true).

       

      What am I missing?  Any advice on how to handle a situation like this?

        • 1. Re: Allow user-created data in empty datagrid?
          Handycam Level 1

          OK, so far I am trying it like this: I have created an object to hold each row of data

          private var exclusionEntry:Object = {units:0,width:0,height:0};
          [Bindable] private var exclusionData:ArrayCollection = new ArrayCollection([exclusionEntry]);
          

           

          And then a button to add a new row to the grid as the user needs to:

          protected function addRow_clickHandler(event:MouseEvent):void{
               exclusions.rowCount += 1;
               exclusionData.addItem(exclusionEntry);
          }
          

           

          Which sort of works but creates a copy of the same object instead of a new "empty" exclusion entry that can be edited separately.

          • 2. Re: Allow user-created data in empty datagrid?
            Handycam Level 1

            I modified this function to be:

            protected function addRow_clickHandler(event:MouseEvent):void
                           {
                                exclusions.rowCount += 1;
                                var obj:Object = new Object();
                                obj.units = 0;
                                obj.width = 0;
                                obj.height = 0;
                                exclusionData.addItem(obj);
                           }
            

             

            and it seems to work.  Not sure if this is the best way, though.  Feels a little kludgy.