6 Replies Latest reply on Dec 15, 2009 9:24 PM by Flex harUI

    Subclassing DataGridColumn to add styles?

    msakrejda Level 4

      I'd like to extend DataGridColumn to provide styleable formatting (rather than just using labelFunction) and some other minor features via styles. The Flex docs say that I should override styleChange(styleProp:String) on UIComponent, but DataGridColumn extends CSSStyleDeclaration and not UIComponent, so that does not apply. Should I just override setStyle? Do I need to chain the call to super when handling changes to my own styles? If so, should I call this before or after I do my changes?

        • 1. Re: Subclassing DataGridColumn to add styles?
          Flex harUI Adobe Employee

          I haven't looked at my code for this in a while.  Did you look at the examples on my blog?

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Subclassing DataGridColumn to add styles?
            msakrejda Level 4

            Apparently not carefully enough. Although I went back to look at it,

            and I don't see anything dealing with styles and DataGridColumn.  I

            looked at "Thinking About Item Renderers", the dg footer posts, and

            the checkbox dg editor. These seem to use properties exclusively; I

            need to use styles since I need to support an external CSS swf

            configuration of these properties.

            • 3. Re: Subclassing DataGridColumn to add styles?
              Flex harUI Adobe Employee

              I might be misunderstanding what you're trying to achieve.  Are you trying to define new styles on a DGColumn?  I think all you need is metadata.  From AS you can setStyle() anything you want since metadata is not checked.  Then it is up to the renderer to getStyle.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              1 person found this helpful
              • 4. Re: Subclassing DataGridColumn to add styles?
                msakrejda Level 4

                I see. Although the styles I'm most interested in are related to extending the properties of the DataGridColumn itself with styles. E.g., suppose I want to add a C-style format String via a formatString style to DataGridColumn (this would be used if labelFunction is not present). Looking at the DataGridColumn source, I'd need to override DataGridColumn.itemToLabel() for the actual labeling logic, but I'm not sure what the proper way of handling the style itself is. The other style I'd like to add is for providing something similar for sortCompareFunction. Both of these are properties of the DataGridColumn itself rather than being interpreted externally by the DataGrid or the DataGridItemRenderer.

                • 5. Re: Subclassing DataGridColumn to add styles?
                  msakrejda Level 4

                  To be clear, here's a simplified version of my code:

                   

                  public class TableColumn extends DataGridColumn {

                      public override function setStyle(styleProp:String, value:Object):void {

                          // call super.setStyle(styleProp, value) here?

                          if (styleProp == 'sort') {

                              // do my sort stuff

                          }  else if (styleProp == 'format') {

                              // do my format stuff

                          } else {

                              // or call super.setStyle here?

                          }

                          // or here?

                      }

                  }

                  • 6. Re: Subclassing DataGridColumn to add styles?
                    Flex harUI Adobe Employee

                    I think of DataGridColumns as being relatively passive.  You can set styles on them and not need to act on it right away.  Just call invalidateList on the DG and the new styles will get used when validation updates the renderers.

                     

                    So, you probably don't need to override setStyle for formatString at all.  InvalidateList will be called for you and then your override of itemToLabel will be called.

                     

                    For the sort style, it depends on what it does.  If it affects the renderer then again, you don't need to override setStyle, but if you need to modify a sort for the dataProvider then you would and update the DP in the override.  I'd always call super.setStyle() in an override, probably on the first line.

                     

                    Alex Harui

                    Flex SDK Developer

                    Adobe Systems Inc.

                    Blog: http://blogs.adobe.com/aharui