Thats what the filter function does, unless I missed something. The problem I am seeing is that a whole new datagrid, with a whole new dataprovider, created with a whole different line of code. That dataGrid.columns (different ID) is returning the first datagrids columns.
--- In flexcoders@yahoogroups.com, "Tracy Spratt" <tr...@...> wrote: > > DataGrid.columns returns a copy of the columns array. Be sure you re-assign > the modified array to the columns property. > > > > Tracy Spratt, > > Lariat Services, development services available > > _____ > > From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On > Behalf Of invertedspear > Sent: Monday, December 14, 2009 10:20 AM > To: flexcoders@yahoogroups.com > Subject: [SPAM] [flexcoders] Re: Crazy problem with a script creating > datagrids > > > > > > The problem is I have to create them programatically since the number of > them will be different based on the returned data. I found a workaround > where I call the filter after I assign the column dataFields names I want. > But I'm still doing all these actions on an array that starts off with all > the wrong values. > > --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, > Alex Harui <aharui@> wrote: > > > > In general, you should manipulate the columns of a DataGrid at setup other > than maybe to change visible. The recommended practice at setup is to create > a fresh array of DataGridColumns and assign the whole array to the columns > property. > > > > Alex Harui > > Flex SDK Developer > > Adobe Systems Inc.<http://www.adobe. <http://www.adobe.com/> com/> > > Blog: http://blogs. <http://blogs.adobe.com/aharui> adobe.com/aharui > > > > From: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com > [mailto:flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com] > On Behalf Of invertedspear > > Sent: Friday, December 11, 2009 2:51 PM > > To: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com > > Subject: [flexcoders] Crazy problem with a script creating datagrids > > > > > > > > > > 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,fals > e); > > > 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_templateIcd9 > ID"] > > 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); > > } > > >