`

AdvancedDatagrid改变行的颜色

    博客分类:
  • Flex
 
阅读更多

最早我尝试重写AdvancedDatagrid的drawRowBackGrounds方法,如下:

 

override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number, height:Number, color:uint, dataIndex:int):void 

if(dataProvider){

var hcv:HierarchicalCollectionView = dataProvider as HierarchicalCollectionView ;

var hd:HierarchicalData = hcv.source as HierarchicalData ;

var ac:ArrayCollection = hd.source as ArrayCollection ;

if(ac.length > 0 && dataIndex < ac.length){

var item:AlarmVO = ac[dataIndex] as AlarmVO ;

if(item.activeStatus == "0"){

color = 0xCCCCCC ;

}

}

super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);

}

}

 

存在问题:当有节点打开或关闭的时候,变灰的行是错误的。

 

改进方法来自这里http://www.forestandthetrees.com/2008/10/21/adg-color-rows-by-depth/

用到了之前没了解过的类 HierarchicalCollectionViewCursor 

 

override protected function drawRowBackground (s : Sprite,
            rowIndex : int, y : Number, height : Number, color : uint,
            dataIndex : int) : void
        {
              var dp:HierarchicalCollectionView = dataProvider as
                  HierarchicalCollectionView;
              //if the index is less than the length, the row has no data
              //content
              if (dp != null){
                  if (dataIndex < dp.length) {
                      var cursor : HierarchicalCollectionViewCursor =
                          dp.createCursor() as HierarchicalCollectionViewCursor;
                     cursor.seek(CursorBookmark.FIRST, dataIndex);
                     var o : Object = cursor.current;
                     switch (cursor.currentDepth) {
                         case 1:
                             color = 0xffcccc;
                             break;
                         case 2:
                             color = 0xccffcc;
                             break;
                         case 3:
                             color = 0xccccff;
                             break;
                     }
                  }
              }
              super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
        }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics