13 Replies Latest reply on Jun 28, 2012 11:43 AM by Code Girl

    Original vs Existing value on Datagrid

    Code Girl Level 1

      I have a datagrid which in some columns I have itemeditors with combo boxes and datefields and other columns I just have an editable datafield.  But since the fields are bound to an instance of a value object when someone changes the value, it is changed in the instance as well.  Is there a property that keeps track of the original value before the value was modified?  Is there a modified property to tell me if a value has changed.  Or do I need to create some kind of focus function to save values in variables?  What is the thinking for flex?

        • 1. Re: Original vs Existing value on Datagrid
          drkstr_1 Level 4

          I usually handle this in the underlying data model class. There are also the DataGrid itemEditBegin, itemEditBeginning, and itemEditEnd events.

          1 person found this helpful
          • 2. Re: Original vs Existing value on Datagrid
            Code Girl Level 1

            the underlying array is automatically changed as soon as it is changed in the datagrid since the data is bound.  On the Item edit, is this row based or an individual column for a row?  I have seen three other options but seemed kinda dirty.  The change event for the datagrid.  But this only fires when someone changes rows.  It does not fire on initial load or if someone removes an item and the next item is selected.  I forget what the other two were but one of them was used with AS2.  Will look into the Collection events you just meantioned.

            • 3. Re: Original vs Existing value on Datagrid
              Code Girl Level 1

              found an article about itemeditbegin and exactly what I was trying to accomplish

               

              http://www.adobe.com/devnet/flash/articles/detecting_datagrid_edits.html

              • 4. Re: Original vs Existing value on Datagrid
                Code Girl Level 1

                According to the article, Flex does not have a built in way of determining a previous value.  Too bad.   Hopefully there are no draw backs to the method suggested in the article.

                • 5. Re: Original vs Existing value on Datagrid
                  Code Girl Level 1

                  Bummer, this did not fix my issue.  The above suggestion only works if only one column is being addressed.  but in my case, Each row contains a value based upon a category.  So, if the category changes then you need to change the value from the old category and add to the new.  If the value changes then you subtract the old and add the new.  If both changes then you remove the old value out of the old category and then add the new value to the new category.  So, this solution does not work.  The bummer part is now the Adobe employees will ignore this issue because there are posts to it.  I guess I will have to start a new discussion.

                  • 6. Re: Original vs Existing value on Datagrid
                    Code Girl Level 1

                    My Bad.

                    since my tmpObject was not a value object, I forgot to instantiate the object and that is why it didnt work.  So the solution above does solve my problem.  Though not as clean as I would like but clean enough.

                    • 7. Re: Original vs Existing value on Datagrid
                      drkstr_1 Level 4

                      IMHO, the clean solution would be to handle this in the data model (your value object class).

                       

                      Something along these lines:

                       

                      public class MyModel

                      {

                       

                                private var _dataChanged:Boolean;

                       

                                public function get dataChanged():Boolean

                                {

                                          return _dataChanged;

                                }

                       

                                private var _someProperty:String;

                       

                                public function get someProperty():String

                                {

                                          return _someProperty;

                                }

                       

                                public function set someProperty(value:String):void

                                {

                                          if(_someProperty == value)

                                                    return;

                       

                                          _someProperty = value;

                                          _dataChanged = true;

                                          //and maybe dispatch some event, or hook up binding, etc.

                                }

                      }

                       

                      This would allow you to perform logic when the values are edited (like storing the old values for a roll back).

                      • 8. Re: Original vs Existing value on Datagrid
                        tinylion_uk Level 2

                        That’s exactly what I do

                        • 9. Re: Original vs Existing value on Datagrid
                          Code Girl Level 1

                          One day, I need to learn this aspect of Flash builder.  But, I am currently using a web service Java Bean and flash builder is building my value objects for me through the wsdl.  So, if I were to modify the class and import when I make a change to the web service then my changes would be lost.  But thanks for the suggestion. 

                          • 10. Re: Original vs Existing value on Datagrid
                            drkstr_1 Level 4

                            The auto generated classes are set up so you can extend them into full blown "models" (a value object with business logic). Only the base classes will be replaced when they are generated.

                            • 11. Re: Original vs Existing value on Datagrid
                              Code Girl Level 1

                              Sounds like something I need to learn.  Would you have any examples?

                              • 12. Re: Original vs Existing value on Datagrid
                                drkstr_1 Level 4

                                I dug this out of an old project. Both BoardModel and _Super_BoardModel (not shown) were generated by the Flex data service wizard. I added changes to the BoardModel class after it was generated to give it a bit of business logic. If I were to change the model and regenerate the classes, only _Super_BoardModel will be replaced, while my edits to BoardModel would stay intact.

                                 

                                Keep in mind of course, that if you make changes to the model that affect a property you are extending, you will need to make the update manually in your extended class as well.

                                 

                                public class BoardModel extends _Super_BoardModel
                                {
                                    /**
                                     * DO NOT MODIFY THIS STATIC INITIALIZER - IT IS NECESSARY
                                     * FOR PROPERLY SETTING UP THE REMOTE CLASS ALIAS FOR THIS CLASS
                                     *
                                    **/
                                
                                    /**
                                     * Calling this static function will initialize RemoteClass aliases
                                     * for this value object as well as all of the value objects corresponding
                                     * to entities associated to this value object's entity.
                                     */
                                    public static function _initRemoteClassAlias():void
                                    {
                                        _Super_BoardModel.model_internal::initRemoteClassAliasSingle(com.
                                            t8.models.BoardModel);
                                        _Super_BoardModel.model_internal::initRemoteClassAliasAllRelated();
                                    }
                                
                                    model_internal static function initRemoteClassAliasSingleChild():void
                                    {
                                        _Super_BoardModel.model_internal::initRemoteClassAliasSingle(com.
                                            t8.models.BoardModel);
                                    }
                                
                                    {
                                        _Super_BoardModel.model_internal::initRemoteClassAliasSingle(com.
                                            t8.models.BoardModel);
                                    }
                                
                                    //----------------------------------------------------------
                                    //
                                    //
                                    //   Class Properties 
                                    //
                                    //
                                    //----------------------------------------------------------
                                
                                    //--------------------------------------
                                    // Public Properties 
                                    //--------------------------------------
                                
                                    override public function set isTwin(value:Boolean):void
                                    {
                                        super.isTwin = value;
                                
                                        //if this is a twin, make sure tail length matches running length
                                        if(value && this.tailLength != this.noseLength)
                                        {
                                            this.tailLength = this.noseLength;
                                        }
                                    }
                                
                                    /**
                                     * END OF DO NOT MODIFY SECTION
                                     *
                                     **/
                                
                                    ////////////////////////////////////////////
                                    ////////////////////////////////////////////
                                    ////
                                    //// --== Public Vars ==--
                                    ////
                                    ////////////////////////////////////////////
                                    ////////////////////////////////////////////
                                
                                    override public function set length(value:int):void
                                    {
                                        super.length = value;
                                        updateRunningLength();
                                    }
                                
                                    public function get noseBottom():Point
                                    {
                                        return new Point(this.noseBottomX, this.noseBottomY);
                                    }
                                
                                    override public function set noseLength(value:int):void
                                    {
                                        super.noseLength = value;
                                
                                        if(this.isTwin)
                                        {
                                            super.tailLength = value;
                                        }
                                
                                        updateRunningLength();
                                    }
                                
                                    public function get noseTop():Point
                                    {
                                
                                        return new Point(this.noseTopX, this.noseTopY);
                                    }
                                
                                    public function get tailBottom():Point
                                    {
                                        return new Point(this.tailBottomX, this.tailBottomY);
                                    }
                                
                                    override public function set tailLength(value:int):void
                                    {
                                        super.tailLength = value;
                                
                                        //tail cannot be longer then nose
                                        if(this.isTwin || value > this.noseLength)
                                        {
                                            super.noseLength = value;
                                        }
                                
                                        updateRunningLength();
                                    }
                                
                                    public function get tailTop():Point
                                    {
                                        return new Point(this.tailTopX, this.tailTopY);
                                    }
                                
                                    ////////////////////////////////////////////
                                    ////////////////////////////////////////////
                                    ////
                                    //// --== Internal Methods ==--
                                    ////
                                    ////////////////////////////////////////////
                                    ////////////////////////////////////////////
                                
                                    protected function updateRunningLength():void
                                    {
                                        this.runningLength = this.length - this.noseLength -
                                            this.tailLength;
                                    }
                                }
                                


                                1 person found this helpful
                                • 13. Re: Original vs Existing value on Datagrid
                                  Code Girl Level 1

                                  Duh.  about as obvious as it gets.  Funny how when I think Flash, Java seems to fade away.  hehehehhe  Thank You.