?
Solved

AdvancedDatagrid Footer visibility issue

Posted on 2009-02-12
3
Medium Priority
?
2,336 Views
Last Modified: 2012-05-06
I have an AdvancedDatagrid with footer to show the summary. I want to set the grid column and footer column visiblity off by visible="false".

This works for the grid column but bot working for the footer column.

The source code attached . Any help appreciated.

Thanks
First as file
package com.forestandthetrees.controls.adgFooter
{
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Sprite;
 
import mx.controls.AdvancedDataGrid;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.UIComponent;
import mx.core.mx_internal;
import mx.events.AdvancedDataGridEvent;
use namespace mx_internal;
import mx.controls.Alert;
 
public class AdvancedDataGridFooter extends UIComponent
{
 
	public function AdvancedDataGridFooter()
	{
		super();
	}
 
	protected var overlayFixed:Sprite;
	protected var overlayScrollable:Sprite;
 
	protected var dataGrid:AdvancedDataGrid;
	
	/**
	 *  create the actual border here
	 */
	override protected function createChildren():void
	{
		dataGrid = parent as AdvancedDataGrid;
		
		overlayFixed = new Sprite();
		addChild(overlayFixed);
		
		overlayScrollable = new Sprite();
		addChild(overlayScrollable);
		//
		dataGrid.addEventListener(AdvancedDataGridEvent.COLUMN_STRETCH,
			_handleColumnStretch);
	}
	private function _handleColumnStretch (e : AdvancedDataGridEvent) : void {
		_drawFixedColumns = false;
	}
	//you only need to draw the fixed columns on init and when the columns
	//are resized
	private var _drawFixedColumns : Boolean = false;
	/**
	 *	lay it out
	 */
	override protected function updateDisplayList(w:Number, h:Number):void
	{
		overlayScrollable.graphics.clear();
		if (!_drawFixedColumns){
    		overlayFixed.graphics.clear();
		}
      	var lockedColumns : int = dataGrid.lockedColumnCount;
 
		// destroy the old children - except the grid lines and the mask
		// if there is no mask, only keep the the grid lines (level 0),
		// if there is a mask, keep mask (level 0) and grid lines (level 1)
		var childrenToKeep : int = 2;
		if (_drawFixedColumns) childrenToKeep += lockedColumns;
		if (dataGrid.getStyle("horizontalScrollPolicy") != "off") {
			childrenToKeep ++;
			_updateMask (w, h);
		}
			while (numChildren > childrenToKeep) removeChildAt(childrenToKeep);
     
		// make new ones
		var cols:Array = dataGrid.columns;
		
 
      var lineCol:uint = dataGrid.getStyle("verticalGridLineColor");
      var vlines:Boolean = dataGrid.getStyle("verticalGridLines");
		overlayFixed.graphics.lineStyle(1, lineCol);
		overlayScrollable.graphics.lineStyle(1, lineCol);
    
		var xx:Number = 0;
		var yy:Number = 0;
		var i : int = 0;
		var col:AdvancedDataGridColumn;
		//draw the locked columns if there are any
		while (xx < w && i < lockedColumns)
		{
			col = cols[i++];
         if (!_drawFixedColumns) {
    			_drawColumn(col, overlayFixed, i, xx, yy, h);	
			}
			xx += col.width;
			
		}
		_drawFixedColumns = true;
		//draw the scrollable columns
		i = dataGrid.horizontalScrollPosition + lockedColumns;
		while (xx < w && i < cols.length )
		{
			col = cols[i++];
			_drawColumn(col, overlayScrollable, i, xx, yy, h);
			xx += col.width;
		}
		
      lineCol = dataGrid.getStyle("horizontalGridLineColor");
      if (dataGrid.getStyle("horizontalGridLines")) {
			overlayFixed.graphics.lineStyle(1, lineCol);
			overlayFixed.graphics.moveTo(0, yy);
			overlayFixed.graphics.lineTo(w, yy);
		}
 
		// draw separator at top of footer
      lineCol = dataGrid.getStyle("borderColor");
		overlayFixed.graphics.lineStyle(1, lineCol);
		overlayFixed.graphics.moveTo(0, 0);
		overlayFixed.graphics.lineTo(w, 0);
 
	}
	private function _drawColumn (col:AdvancedDataGridColumn,
	    drawSprite : Sprite, i : int, xx : Number, yy : Number, h : Number) : 
	    void 
	{
	    if (col is FooterAdvancedDataGridColumn) {
			var fdgc:FooterAdvancedDataGridColumn = col as 
			    FooterAdvancedDataGridColumn;
			fdgc.footerColumn.owner = fdgc.owner;
			var renderer:IListItemRenderer = (fdgc.footerColumn.itemRenderer) ? 
				fdgc.footerColumn.itemRenderer.newInstance() :
				dataGrid.itemRenderer.newInstance();
			renderer.styleName = fdgc.footerColumn;
			if (renderer is IDropInListItemRenderer) {
				IDropInListItemRenderer(renderer).listData = 
					new AdvancedDataGridListData(
					(fdgc.footerColumn.labelFunction != null) ? 
		         fdgc.footerColumn.labelFunction(col) 
					: fdgc.footerColumn.headerText, 
					fdgc.dataField, i - 1, null, dataGrid, -1);
			}
			renderer.data = fdgc;
			addChild(DisplayObject(renderer));
			renderer.x = xx;
			renderer.y = yy;
			renderer.setActualSize(col.width - 1, dataGrid.rowHeight);
			if (dataGrid.getStyle("verticalGridLines"))
			{
				drawSprite.graphics.moveTo(xx + col.width, yy);
				drawSprite.graphics.lineTo(xx + col.width, h);
			}
		}
	}
	private var _myMask : Sprite;
	/**
	 * Does two things : creates the mask if it's needed
	 * Updates the mask size based on the new size properties
	 */
	private function _updateMask (w : Number, h : Number) : void {
		//if the mask hasn't been created, create it
		if (_myMask == null) {
			_myMask = new Sprite();
			//need to add it at 1 because horizontal scroll policy could 
			//change at run time, and the removal of the text is based on
			//child index
			addChildAt(_myMask, 1);
			mask = _myMask;
		}
		var g : Graphics = _myMask.graphics;
		g.clear();
		g.beginFill(0xffffff, 0);
		g.drawRect(0, 0, w, h);
		g.endFill();
	}
}
 
}
//////////////////////////
2 nd
 
package com.forestandthetrees.controls.adgFooter
{
import mx.controls.AdvancedDataGrid;
 
public class FooterAdvancedDataGrid extends AdvancedDataGrid
{
 
	public function FooterAdvancedDataGrid()
	{
		super();
	}
 
    protected var footer:AdvancedDataGridFooter;
 
	protected var footerHeight:int = 22;
 
    override protected function createChildren():void
    {
        super.createChildren();
 
        if (!footer)
        {
            footer = new AdvancedDataGridFooter();
            footer.styleName = this;
            addChild(footer);
        }
       
    }
    
    
    override protected function adjustListContent(unscaledWidth:Number = -1,
                                       unscaledHeight:Number = -1):void
    {
		super.adjustListContent(unscaledWidth, unscaledHeight);
 
		listContent.setActualSize(listContent.width, listContent.height - footerHeight);
		
		footer.setActualSize(listContent.width, footerHeight);
		footer.move(listContent.x, listContent.y + listContent.height + 1);
		
		
	}
 
	override public function invalidateDisplayList():void
	{
		super.invalidateDisplayList();
		if (footer)
			footer.invalidateDisplayList();
	}
}
 
}
 
///////////
3rd
 
package com.forestandthetrees.controls.adgFooter
{
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
 
 
[DefaultProperty("footerColumn")]
 
public class FooterAdvancedDataGridColumn extends AdvancedDataGridColumn
{
 
	public function FooterAdvancedDataGridColumn()
	{
		super();
		this.visible = footerColumn.visible;
	}
	public var footerColumn:AdvancedDataGridColumn = new AdvancedDataGridColumn();
		
 
}
        
}
 
///////////// MXML //////////
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:local="*" 
    width = "100%" 
    xmlns:adg="com.forestandthetrees.controls.adgFooter.*">
 
<mx:Script>
<![CDATA[
    import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
 
private var dp:Array = [
    { symbol: "ADBE", name: "Adobe Systems Inc.", price: 49.95, age:10 },
    { symbol: "BETA", name: "Beta Inc.", price: 19.95, age:10 },
    { symbol: "CSCO", name: "Cisco Inc.", price: 45.95, age:10 },
    { symbol: "DELL", name: "Dell Inc.", price: 34.95, age:10 },
    { symbol: "EXPD", name: "Expedia Inc.", price: 39.95, age:10 },
    { symbol: "FOXS", name: "Fox Sports Inc.", price: 9.95, age:10 },
    { symbol: "GOOG", name: "Google Inc.", price: 139.95, age:10 },
    { symbol: "ICON", name: "Icon Inc.", price: 32.95, age:10 },
    { symbol: "JUNI", name: "Juniper Inc.", price: 23.95 , age:10},
    { symbol: "KLA", name: "KLA Tencor Inc.", price: 37.95, age:10 },
    { symbol: "MACR", name: "Macromedia Inc.", price: 39.95, age:10 },
    { symbol: "MSFT", name: "Microsoft Corp.", price: 25.95, age:10 },
    { symbol: "IBM", name: "IBM Corp.", price: 42.55, age:10 }
    ];
 
//    public function averageFunction(col:DataGridColumn):String
//    {
//        var n:int = dp.length;
//        var avg:Number = 0;
//        for (var i:int = 0; i < n; i++)
//        {
//            avg += dp[i][col.dataField];
//        }
//        avg /= n;
//        return "AVG: " + avg.toFixed(2);
//    }
 
    public function averageFunctionADG1(col:AdvancedDataGridColumn):String
    {
        
        return "";
    }
 
    public function averageFunctionADG(col:AdvancedDataGridColumn):String
    {
        var n:int = dp.length;
        var avg:Number = 0;
        for (var i:int = 0; i < n; i++)
        {
            avg += dp[i][col.dataField];
        }
        avg /= n;
        return "AVG: " + avg.toFixed(2);
    }
 
]]>
</mx:Script>
<mx:HDividedBox width="100%">
 
    <mx:VBox>
        <mx:Label text="this is the Footer ADG lockedColumnCount=1"/>
    <adg:FooterAdvancedDataGrid id="dg4" initialize="dg4.dataProvider = dp" 
        paddingTop="0" horizontalScrollPolicy="auto"
        paddingBottom="0" verticalAlign="middle" width="50%" 
        lockedColumnCount="0" draggableColumns="true" >
        <adg:columns>
            <adg:FooterAdvancedDataGridColumn    headerText="Name" dataField="name" width="140" >
               <mx:AdvancedDataGridColumn     headerText="Name" dataField="name" /> 
            </adg:FooterAdvancedDataGridColumn>
            <adg:FooterAdvancedDataGridColumn headerText="Symbol" dataField="symbol" width="60" >
            <mx:AdvancedDataGridColumn headerText="Symbol" dataField="symbol"  /> 
            </adg:FooterAdvancedDataGridColumn>
            <adg:FooterAdvancedDataGridColumn headerText="Price" dataField="price" >
              <mx:AdvancedDataGridColumn labelFunction="averageFunctionADG" dataField="price"/> 
           </adg:FooterAdvancedDataGridColumn>
            <adg:FooterAdvancedDataGridColumn headerText="age" dataField="age" visible="true" >
             <mx:AdvancedDataGridColumn dataField="age" labelFunction="averageFunctionADG1"/> 
              
            </adg:FooterAdvancedDataGridColumn>
        </adg:columns> 
    </adg:FooterAdvancedDataGrid>
    </mx:VBox>
</mx:HDividedBox>
 
</mx:Application>

Open in new window

0
Comment
Question by:VKN9876
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 1000 total points
ID: 23631942
In method AdvancedDataGridFooter.updateDisplayList()

...
            while (xx < w && i < lockedColumns)
            {
                  col = cols[i++];
                  if (!col.visible)             // <<<<<<<<<<<<<<  Added
                              continue;             // <<<<<<<<<<<<<<  Added
                       if (!_drawFixedColumns) {
                      _drawColumn(col, overlayFixed, i, xx, yy, h);      
                  }
                  xx += col.width;
                  
            }

and

...

            while (xx < w && i < cols.length )
            {
                  col = cols[i++];
                  if (!col.visible)      // <<<<<<<<<< Added
                        continue;     // <<<<<<<<<< Added
                  _drawColumn(col, overlayScrollable, i, xx, yy, h);
                  xx += col.width;
            }


Then you can write:

        <local:columns>
            <local:FooterAdvancedDataGridColumn    headerText="Name" dataField="name" width="140" visible="false">
               <mx:AdvancedDataGridColumn     headerText="Name" dataField="name" />
            </local:FooterAdvancedDataGridColumn>
             ....

and the Name column ànd footer will disappear. Same for other columns of course.
0
 

Author Closing Comment

by:VKN9876
ID: 31546228
Thank You for your help
0
 
LVL 37

Expert Comment

by:zzynx
ID: 23646302
Thanx 4 axxepting
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question