"This is where I also manualy populate the event.itemRenderer.data = "some text"..."
I don't think you want to do that. You want to update the dataProvider item, and let the framework handle the itemRenderer. "... (the itemEnd handler expects this to be XML it seems)..." In that sentence, what does "this" refer to? Tracy Spratt Lariat Services Flex development bandwidth available ________________________________ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of tntomek Sent: Friday, January 30, 2009 8:49 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Bug in ADG?, possible to bind labelFunction to editor with no dataField? --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Tracy Spratt" <tspr...@...> wrote: > > If you know that "var data:Object = event.itemRenderer.data;" contains a > string, why not just use toString() to put the string value in a string > variable?: > > > > > > And I am not quite following you otherwise. What are you truing to do > with describeType()? That is usually used with non-dynamic objects, but > you have a simple 2d indexed array, correct? You said, "array of rows > and array of cells". Do you mean "array" or do you mean you have nested > dynamic objects? > > > > If you have nested dynamic ovjects, you can examine them with a for-each > or for-in loop. > > > > Note, describeType is "costly". That means slow, so be sure you need > it. It seems like a dangerous thing to do in a lableFunction. > > > > Tracy Spratt > Lariat Services > > Flex development bandwidth available > > ________________________________ > > From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of tntomek > Sent: Thursday, January 29, 2009 6:07 PM > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Bug in ADG?, possible to bind labelFunction to > editor with no dataField? > > > > Hi, > > Does anyone have any idea how to edit data that does not come from > fixed object properties i.e. myObject.Name but myObject.Attributes[2] > which might be name? > > I have a 2D array, array of rows and array of cells for each row, both > are arbitrary. I have this successfully displayed my data in > AdvancedDataGrid via labelFunction. > > public function getContentLabel(item:GridRow, > column:CustomLabelColumn) : String > { > if(item != null) > { > return item.Cells.getGridLabelCellAt(column.columnIndex).Label; > } > else > { > return null; > } > } > > How do I edit the data in these columns? > I looked at > http://www.adobe.com/livedocs/flex/3/html/help.html?content=celleditor_8 <http://www.adobe.com/livedocs/flex/3/html/help.html?content=celleditor_ 8> > .html#197235 > <http://www.adobe.com/livedocs/flex/3/html/help.html?content=celleditor_ <http://www.adobe.com/livedocs/flex/3/html/help.html?content=celleditor_ > > 8.html#197235> > and tried messing around with itemEditBegin and itemEditEnd. I have > itemEditBegin working successfully where I am able to display my label > in a text box. The itemEditEnd for ADG seems to crash because I'm > using typed objects instead of plan strings or XML. > > In fact I'm convinced there is a bug in the itemEnd base handler. I > tried calling preventDefault from the grids itemEnd function but no > luck, I am forced to overwrite the event.reason so that the base class > doesnt destroy my itemEditor. > > My issue is here: > > In AdvancedDataGridBaseEx.as > > private function > itemEditorItemEditEndHandler(event:AdvancedDataGridEvent):void > ........... > > var newData:Object = > itemEditorInstance[_columns[event.columnIndex].editorDataField]; > var property:String = _columns[event.columnIndex].dataField; > var data:Object = event.itemRenderer.data; > var typeInfo:String = ""; > > //WHY is this only XML??? my "data" variable has plan String text and > yet I never make it into the typeInfo == String part since typeInfo is > "" because the XML loop never executes on an object; > > for each(var variable:XML in describeType(data).variable) > { > if (property == variab...@... > <mailto:variable.%40name.toString> ()) > { > typeInfo = variab...@... <mailto:variable.%40type.toString> > (); > break; > } > } > if (typeInfo == "String") > { > //NEVER make it here > if (!(newData is String)) > newData = newData.toString(); > } > //.......... > //CRASH HERE since property is null. > // data = "Some Text"; > if (data[property] != newData) > { > bChanged = true; > data[property] = newData; > } > The code I described is in Flex DMV code, AdvancedDataGridBaseEx.as itemEndHandler. This is a private method and contains some private class variables so I'm not able to modify it's implementation. At first I tried to event.preventDefault() in my local handler but this implementation seems to do important stuff, I dont feel comfortable skipping this code but maybe I should. In addition, this method seems to make use of event.reason in addition to preventDefault. The array is not simple in that its a typed ArrayCollection of rows which each row having a typed ArrayCollecton of cells. So to get at an instance of a cell I go: var cell:MyTypedCell = typedArrayCollectionRows.getMyTypedRowAt(0).Cells.getMyTypedCellAt(0) I was able to handle the itemBegin handler and put a cell.Label value and in TextInput.text. This is where I also manualy populate the event.itemRenderer.data = "some text" (the itemEnd handler expects thi to be XML it seems). So I can successfully display the editing portion of ADG. Where I get into trouble is the default handler for itemEnd. I'm not sure what to do in regards to cleanup and preventing the default from firing. Note that I'm only using the default ADG item renderer for now so I'd like to stick with default implementation as much as possible. I will try to upload a complete simplified project if you would be so kind as to take a look at this issue and maybe a better best practice. Thank you for the reply,