This is driving me nuts. This script is adding datagrids to various containers
in an accordion. In my first level for-each loop the item that fills my
"if(compone...@component_componentid == "999999999")" is the last item looped
through everything works fine except the datagrid I am building there has the
wrong columns. For some reason "tempGridicd9.columns" array is returning the
columns array from the tempGrid variable, and not even the version I end up
with after the filter, but the original columns array. I don't even see how
this is possible.
Then when they datagrid gets drawn it has the right data in it, but it has
extra columns, cause the items from the else statement have 4 more columns.
I have done hours of trouble shooting on this so far. The problem will not
present itself if I do not assign a dataProvider to tempGrid, for some reason
that seems to be where it all blows up.
Anyone have a clue what's going on? Either I've majorly screwed up or this is a
major bug. Please help!!
Here's a simple example of the XML, the real thing has a lot more nodes and a
lot of attributes:
<component>
<question>
<answer/>
</question>
</component>
<component>
<icd9/>
</component>
Script With the Problem
public function populateTemplate():void{
accComponents.removeAllChildren();
for each(var component:XML in XMLTemplate.template.children()){
var newVBox:VBox = new VBox();
newVBox.id = compone...@component_name;
newVBox.label = compone...@component_longname;
newVBox.width = 388;
newVBox.percentHeight = 100;
accComponents.addChild(newVBox);
if(compone...@component_componentid == "999999999"){//icd9component
var tempGridicd9:DataGrid = new DataGrid();
tempGridicd9.setStyle("borderStyle","none");
tempGridicd9.dataProvider = component.children();
tempGridicd9.validateNow();
//tempGridicd9.columns =
tempGridicd9.columns.filter(newTempGridicd9ColFilter);
tempGridicd9.id = 'gridICD9';
tempGridicd9.headerHeight = 0;
tempGridicd9.selectable = false;
tempGridicd9.percentWidth = 100;
tempGridicd9.percentHeight = 100;
tempGridicd9.variableRowHeight = true;
tempGridicd9.columns[0].dataField = "@icd9_color";
tempGridicd9.columns[0].width = 25;
tempGridicd9.columns[0].itemRenderer = new ClassFactory(icdDot);
tempGridicd9.columns[1].dataField = "@icd9_icd9";
tempGridicd9.columns[1].width = 60;
tempGridicd9.columns[2].dataField = "@templateIcd9_name";
tempGridicd9.columns[2].width = 283;
tempGridicd9.columns[2].wordWrap = true;
tempGridicd9.columns[3].dataField =
"@templateIcd9_templateIcd9ID";
tempGridicd9.columns[3].visible = false;
newVBox.addChild(tempGridicd9);
}else if(component.children().length()>0){
for each (var section:XML in component.children()){
var newPanel:Panel = new Panel();
newPanel.title = secti...@sectiontype_name + ": " +
secti...@section_name;
newPanel.width = 368;
newPanel.id = secti...@section_sectionid;
newPanel.data = secti...@section_sortorder;
newPanel.addEventListener(MouseEvent.CLICK,panelClick,false,100,false);
newPanel.addEventListener(MouseEvent.MOUSE_OVER,sectMouseOver,false,100,false);
newPanel.addEventListener(MouseEvent.MOUSE_OUT,sectMouseOut,false,100,false);
newVBox.addChild(newPanel);
if(section.children().length()>0){
var tempGrid:DataGrid = new DataGrid();
var tempGridList:XMLList = section.children();
tempGridList =
tempGridList.(@questionType_name!="null");
tempGridList =
tempGridList.(@question_hideByUserID=="null");
tempGrid.dataProvider = tempGridList;
tempGrid.columns =
tempGrid.columns.filter(tempGridColFilter);
tempGrid.id = 'grid'+ secti...@section_sectionid
//There is a bug that prevents only showing one
line with this:tempGrid.showHeaders = false;
//use below instead
tempGrid.headerHeight = 0;
tempGrid.width = 348;
tempGrid.columns[0].dataField="@questionDisplay";
tempGrid.columns[1].dataField="@question_questionID";
tempGrid.columns[1].visible=false;
tempGrid.columns[2].dataField="@question_sortOrder";
tempGrid.columns[2].visible=false;
tempGrid.rowCount = tempGridList.length();
tempGrid.addEventListener(MouseEvent.CLICK,qDgClick,true,1,false);
newPanel.addChild(tempGrid);
}
}
}
}
}
//This is an addon to the above function
private function newTempGridicd9ColFilter(element:*, index:int,
arr:Array):Boolean{
var quickArrayicd9:Array =
["@icd9_color","@icd9_icd9","@templateIcd9_name","@templateIcd9_templateIcd9ID"]
return (quickArrayicd9.indexOf(element.dataField) != -1);
}
private function tempGridColFilter(element:*, index:int, arr:Array):Boolean{
var quickArray:Array =
["@questionDisplay","@question_sortOrder","@question_questionID"]
return (quickArray.indexOf(element.dataField) != -1);
}