HI All,
I am new to flex and learning on the job and also under time pressure to
finish the work,,
I hava an Array in which a parentid is added, which has values as "0" and
non-zero values.
Parent id = 0 means it is the parent, parent id != 0 means that the parent of
the service is that id.
I am setting parent id equal to the service id when parent id = 0, so the
children and parent can be grouped together.
How can i group the data on parent id an show the data in a tree structure
with the parent row which has values and the children under that parent , to
show as children with values in the row.
Now the Array looks like below and I have added the column for Parent to the
grid. Is it required that the parent column in the ADG with dataField
="PService" should be visible?
Thanks for the help.
I am doing a check to set the PService
in the array dp as below.
This will not compile just to show what I am doing where xp has the parent id
from the Array.
var xp:String= (Xs[i].parentid as String);
if(xp == "0")
{
xp = xd[0];
PService=xp;
}
dp.addItem( { "Index":xd[0] , "Service":xd[ 1], "Priority":xd[ 2], "Current
SLA":xd[3]," Health":xd[ 4], "Quality":xd[ 5],
"Risk":xd[6] , "Avail":xd[7] , "OpMode":xd[ 8],
"dd":ddArr," PService" :PService} );
<?xml version="1.0" ?>
<!-- Dashboard Main Service Summary table -->
<mx:Application xmlns:mx="http://www.adobe. com/2006/ mxml" width="100%"
height="100% " backgroundColor= "#FFFFFF"
initialize=" initApp() ;" creationComplete= "onCreationCompl
ete();">
<mx:Style>
.hStyle { fontWeight:bold; fontFamily:Verdana; fontSize:12; align:center; }
</mx:Style>
<mx:Script>
<![CDATA[
import com.adobe.serializa tion.json. JSON;
import flash.events. Event;
import flash.events. TimerEvent;
import flash.external. ExternalInterfac e;
import flash.utils. Timer;
import mx.collections. ArrayCollection;
import mx.controls. AdvancedDataGrid ;
import mx.controls. advancedDataGrid Classes.Advanced DataGridColumn;
import mx.controls. Alert;
import mx.controls. Image;
import mx.resources. IResourceManager ;
import mx.resources. ResourceManagerI mpl;
import mx.rpc.events. ResultEvent;
import mx.rpc.events. FaultEvent;
import mx.controls. advancedDataGrid Classes.* ;
import mx.controls. *;
import mx.events.*;
import mx.controls. Menu;
[Bindable]
public var sURL:String= "";
[Bindable]
public var rURL:String = "";
[Bindable]
public var labels:ArrayCollect ion = null;
[Bindable]
public var cTitle:String = "Services";
[Bindable]
public var userid:String = "1";
[Bindable]
public var dObj:Object= new Object();
private var myTimer:Timer;
private var delay:uint = 30000; // Default 30 secs
private var repcount:uint = 0;
private var date:Date = new Date();
[Bindable]
private var sDate:String = "";
private function initApp( ) : void
{
// Do what FlexModuleFactory does, only by hand.
var rMI:Object = flash.system. ApplicationDomai n.currentDomain.
getDefinition( "mx.resources. ResourceManagerI mpl" );
mx.core.Singleton. registerClass( "mx.resources. IResourceManager ",
Class(rMI) );
}
private function onCreationComplete( ) : void
{
var parm:String = Application. application. parameters. userid;
if ( (parm != null) && (parm.length > 0) ) userid = parm;
buildURL( );
// Alert.show( "URL= " + sURL );
sst.send();
}
private function buildURL( ) : void
{
sURL = "charts/serviceADGT able.swf" ;
}
private function onFaultLoad( event:FaultEvent ) : void
{
Alert.show(" onFaultLoad: " + event.fault. message);
}
private function onJSONLoad( event:ResultEvent ) : void
{
var rawData:String = null;
var bObj:Object = null;
var tObj:Object = null;
var myMenu:Menu;
var dp:ArrayCollection = new ArrayCollection( );
rawData = String( event.result );
gc.source=dpSrv;
gc.refresh() ;
}
[Bindable]
public var ddLink2:ArrayCollec tion = new ArrayCollection( [
{ label1:"Google" , url1:"http://google. com"},{label2: "yahoo",
url2:"http://yahoo. com" }
]);
[Bindable]
public var ddLink1:ArrayCollec tion = new ArrayCollection( [
{ label1:"Hotmail" , url1:"http://hotmail. com" }
]);
[Bindable]
public var dpSrv:ArrayCollecti on = new ArrayCollection( [
{ Index:"450359962738 8358", Service:"GAUSU01- BPV-AAAA" ,
Priority:"Unspecifi ed", CurrentSLA:" 0",
Health:"3", Quality:"0", Risk:"3", Avail:"0%", OpMode:"Production"
,
dd:ddLink2, "parentid":" 4503599627371867 "},
{ Index:"450359962737 1609", Service:"TestBusine ssView",
Priority:"Unspecifi ed", CurrentSLA:" 1",
Health:"2", Quality:"0", Risk:"2", Avail:"0%", OpMode:"Production"
,
dd:ddLink2 , "parentid":" 4503599627371867 "},
{ Index:"450359962737 1606", Service:"Sub1Busine ssView",
Priority:"Unspecifi ed", CurrentSLA:" 2",
Health:"0", Quality:"0", Risk:"0", Avail:"0%", OpMode:"Production"
,
dd:ddLink2,parentid : "0"},
{ Index:"450359962737 1607", Service:"Sub2Busine ssView",
Priority:"Unspecifi ed", CurrentSLA:" 3",
Health:"0", Quality:"0", Risk:"0", Avail:"0%", OpMode:"Production"
,
dd:ddLink1, "parentid":" 4503599627371867 "}
]);
]]>
</mx:Script>
<mx:HTTPService id="sst" resultFormat= "text" result="onJSONLoad( event)"
url="{sURL}" fault="onFaultLoad( event)"/>
<mx:Panel id="panel" title="{cTitle} " width="100%" height="100% "
titleStyleName= "hStyle" headerColors= "[0xC5DFF9, 0xEFF6FF] " >
<mx:AdvancedDataGrid id="srvTable" width="100%" height="100% " color="0x323232"
dragEnabled= "true" dropEnabled= "true"
enabled="true" showHeaders= "true"
displayItemsExpande d="true" variableRowHeight= "true" wordWrap="false"
initialize=" gc.refresh( );" >
<mx:dataProvider>
<mx:GroupingCollecti on id="gc" source ="{dpSrv}">
<mx:grouping>
<mx:Grouping>
<mx:GroupingField name="PService" />
<!--<mx:GroupingField name="Service" />-->
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollect ion>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGrid Column dataField="PService " id="ps"
width="100" visible="true" headerText=" ParentService" textAlign="center"
sortable="true" />
<!--<mx:AdvancedDataGrid Column id="sid" dataField="Index"
headerText=" "/>
<mx:AdvancedDataGrid Column dataField="Service" headerText="
Service" width="100" textAlign="center" sortable="true"
/>-->
<mx:AdvancedDataGrid Column dataField="Priority " headerText="
Priority" width="65" textAlign="center" sortable="true" />
<mx:AdvancedDataGrid Column id ="csla" dataField="Current
SLA" headerText=" Current SLA" width="16" textAlign="center" sortable="true"
/>
<mx:AdvancedDataGrid Column id="hlth" dataField="Health"
headerText=" Health" width="45" textAlign="center" sortable="true" />
<mx:AdvancedDataGrid Column id="qlty" dataField="Quality"
headerText=" Quality" width="45" textAlign="center" sortable="true" />
<mx:AdvancedDataGrid Column id="rsk" dataField="Risk"
headerText=" Risk" width="45" textAlign="center" sortable="true" />
<mx:AdvancedDataGrid Column dataField="Avail" headerText="
Availability [24 hours]" width="45" textAlign="right" />
<mx:AdvancedDataGrid Column dataField="OpMode" headerText="
Operational Mode" width="65" textAlign="left" />
<mx:AdvancedDataGrid Column id ="ddcol" headerText=" Launch To"
width="200" textAlign="left"> <!--itemRenderer= "mx.controls. PopUpButton" -->
</mx:AdvancedDataGri dColumn>
</mx:columns>
<mx:rendererProvider s>
<!-- <mx:AdvancedDataGrid RendererProvider dataField="Index"
depth="2" column="{sid} " columnIndex= "0"
renderer="com. ca.RadioButtonRe nderer"/>-->
<mx:AdvancedDataGrid RendererProvider dataField="Current SLA"
depth="2" column="{csla} " columnIndex= "2"
renderer="mx. controls. Image" />
<mx:AdvancedDataGrid RendererProvider dataField="Health" depth="2"
column="{hlth} " columnIndex= "3"
renderer="mx. controls. Image" />
<mx:AdvancedDataGrid RendererProvider dataField="Quality"
depth="2" column="{qlty} " columnIndex= "4"
renderer="mx. controls. Image" />
<mx:AdvancedDataGrid RendererProvider dataField="Risk" depth="2"
column="{rsk} " columnIndex= "5"
renderer="mx. controls. Image" />
<mx:AdvancedDataGrid RendererProvider dataField="dd"
column="{ddcol} " depth="2" columnIndex= "8" renderer="com. ca.PopUpMenuButt
onRenderer" />
</mx:rendererProvide rs>
</mx:AdvancedDataGri d>
</mx:Panel>
</mx:Application>
this is my AS file
PopUpMenuButtonRend erer.as:
package
{
import flash.net.URLRequest;
import flash.net.navigateToURL;
import mx.controls. PopUpMenuButton;
import mx.events.MenuEvent ;
public class PopUpMenuButtonRenderer extends PopUpMenuButton
{
public function PopUpMenuButtonRend erer()
{
super();
}
override public function set data(value:Object) :void
{
if(value != null)
{
super.data = value;
addEventListener( MenuEvent. ITEM_CLICK, itemClickHandler) ;
label = "Action";
dataProvider = value.dd;
labelField = "label";
}
}
public function itemClickHandler( event:MenuEvent) :void
{
if(event && event.item.url != null)
{
navigateToURL( new URLRequest(event. item.url) , "_blank");
}
}
}
}