5 Replies Latest reply on Feb 18, 2010 9:09 AM by F.Bowman

    DataGrid Value Update


      I have an application - it can be found at http://reactorsoft.ath.cx/Projects/Cygnus_v1/Cygnus_v1.html if reference is needed.


      In this application, I have a DataGrid. What I want to do it update the 3 right-most columns based on the data that is entered into the Act. Earnings column. Ideally, this will be done row by row.


      The problem that I am experiencing is that the value in the DataGrid isn't being updated quickly enough when the itemEditEnd event is triggered. If I come back to that row and update the value that is entered, the old valued will be retrieved. How can I work around this?


      Also, another problem that I'm experiencing is that the triggerEvent value of the itemEndEdit event isn't giving me a value. This is supposed to tell me whether the edit was ended due to a mouse event or a keyboard event. This is also critical to what I'm trying to accomplish.


      Can anyone provide me with any isight into this? It will be very much appreciated.

        • 1. Re: DataGrid Value Update
          archemedia Level 4

          A neat trick: use the callLater method to ensure that the dataProvider has been updated:


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
                      import mx.events.DataGridEvent;
                      import mx.collections.ArrayCollection;
                      private var dp:ArrayCollection;
                      private function init():void
                          var da:Array = [{id: 1, amt: 0, c1:0, c2:0}, {id: 2, amt: 0, c1:0, c2:0}];
                          dp = new ArrayCollection(da);
                      private function calc(evt:DataGridEvent):void
                          var currObject:Object = dp[evt.rowIndex];
                          currObject.c1 = currObject.amt * 2;
                          currObject.c2 = currObject.amt * 1.5;
              <mx:DataGrid x="10" y="10" dataProvider="{dp}" itemEditEnd="callLater(calc, [event])" editable="true">
                      <mx:DataGridColumn headerText="id" dataField="id" editable="false"/>
                      <mx:DataGridColumn headerText="amt" dataField="amt"/>
                      <mx:DataGridColumn headerText="calc1" dataField="c1" editable="false"/>
                      <mx:DataGridColumn headerText="calc2" dataField="c2" editable="false"/>



          Hope this helps,



          • 2. Re: DataGrid Value Update
            F.Bowman Level 2

            Hey Dany, that worked like a charm. Thanks a lot.


            I don't suppose you happen to know why the triggerEvent property of the event is reporting null instead of saying whether it was a keyboard or mouse event?


            If not, I guess I may have to open a separate question for that.


            Thanks again. I'll wait until you respond to assign correct answer so it doesn't show up as answered yet.

            • 3. Re: DataGrid Value Update
              F.Bowman Level 2

              For anyone who would have been wondering, this is how it was done in Flash:-



              • 4. Re: DataGrid Value Update
                archemedia Level 4

                Interesting article!


                I don't know why the triggerEvent doesn't show. You'd have to go in the dataGrid class during debugging to find out when this property is set.

                If I find the time, I might dig in myself...



                • 5. Re: DataGrid Value Update
                  F.Bowman Level 2

                  Thanks a lot once again man. I appreciate it.