2 Replies Latest reply on Aug 7, 2009 6:07 AM by ay713

    AdvancedDataGrid header renderer

    ay713

      I feel like this is a very basic problem and as such it probably has an easy solution, but nevertheless I can't seem to figure it out. I'd like for data (in the cells and in the header) to be truncated (and truncation to be indicated by ellipses "...") when a column is resized to a smaller width and all data can't be displayed. I've seen examples where this is achieved by setting the headerRenderer and itemRenderer properties to mx.control.Label which doesn't work very well for the headers because the sorting controls are lost (I can't multi-sort anymore, because the sorting icons that used to be displayed in each column no longer show up). So now I'm wondering if there's a better way of doing it... Perhaps extending AdvancedDataGridHeaderRenderer and AdvancedDataGridItemRenderer classes but I'm not sure which properties to override.

      Any help would be much appreciated!

        • 1. Re: AdvancedDataGrid header renderer
          ay713 Level 1

          I should also add that I want tooltips to be generated for truncated data, so when a mouse cursor is placed over the truncated text in the header or column cell a tooltip pops up with the complete text. Again, setting renderer to mx.controls.Label seems to do it correctly, but I'd really like to know if there's a way to do the same thing by overriding the AdvancedDataGridHeaderRenderer and AdvancedDataGridItemRenderer classes since that seems to be the proper way of doing it (or at least that's what I'm used to doing in Java)

          • 2. Re: AdvancedDataGrid header renderer
            ay713 Level 1

            Here's what I ended up doing. I hope this helps anyone with a similar issue.

             

            public class HeaderRenderer extends AdvancedDataGridHeaderRenderer
            {
              public function HeaderRenderer()
              {
                super();
              }
            
              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
              {
                if(this.label.truncateToFit("..."))
                {
                  if(this.data != null && this.data is AdvancedDataGridColumn)
                  {
                    var col:AdvancedDataGridColumn = this.data as AdvancedDataGridColumn;
                    this.toolTip = col.headerText;
                    //or alternatively:
                    //this.label.toolTip = col.headerText;
                  }
                }
                super.updateDisplayList(unscaledWidth, unscaledHeight);
              }
            }