6 Replies Latest reply on Jul 12, 2011 11:09 AM by Flex harUI

    DataGrid and labelFunction

    supersorensen

      Hi all!

       

      I have a DataGrid, and I have two columns where i want to manipulate the data shown. I tried using a labelfunction, but it turns out the labelfunction is called each time I focus out, and not only when the DataGrid is initialized.

      I've seen theres an initialize for DataGrid, but how can i use this to manipulate the data from my two columns?

       

      Sincerly

        • 1. Re: DataGrid and labelFunction
          supersorensen Level 1

          more precise, I want a column with type uid, to be presented as strings using some transformation function (but only done once, during init)

          • 2. Re: DataGrid and labelFunction
            Flex harUI Adobe Employee

            That sounds like you want to manipulate the dataProvider, or wrap it and

            cache the transformed value.  I suppose your labelFunction could also cache

            transformed values as well.

            • 3. Re: DataGrid and labelFunction
              supersorensen Level 1

              but I cant manipulate the dataProvider, because the new value is not the same type as in the dataProvider. Thats why I only want the dataGrid to show the manipulated column, not update the dataprovider

              • 4. Re: DataGrid and labelFunction
                Flex harUI Adobe Employee

                You can wrap the dataprovider objects, adding a string version of the

                property.

                 

                You can also encapsulate the labelFunction in the itemRenderer, but it will

                still get called extra times when scrolling and other times the renderers

                get recycled.

                • 5. Re: DataGrid and labelFunction
                  supersorensen Level 1

                  how do I do that?

                  • 6. Re: DataGrid and labelFunction
                    Flex harUI Adobe Employee

                    How do you wrap an object?  It depends on how you are getting your data.  If

                    you are using RemoteObject or can control the data type being sent over the

                    wire, I would simply add a new getter to the data class.

                     

                    The most rudimentary way is something like this:  Say you had a ShoppingCart

                    record:

                     

                    class ShoppingCartRecord

                    {

                        public var catalogID:int;

                    }

                     

                    A wrapper class might look like:

                     

                    class DisplayableShoppingCartRecord

                    {

                        public function DisplayableShoppingCartRecord(orig:ShoppingCartRecord)

                        {

                            original = orig;

                        }

                     

                        public var original:ShippingCartRecord;

                     

                        public function get catalogID():int

                        {

                            return original.catalogID;

                        }

                     

                        private var _displayName:String;

                     

                        public function get displayName():String

                        {

                            if (!_displayName)

                                _displayName = yourOldLabelFunction(orig);

                            return _displayName;

                        }

                    }

                     

                     

                    Then at some point, you loop through the original data set and instantiate

                    the wrapped versions and pass that dataprovider to the datagrid.