--- In flexcoders@yahoogroups.com, "tntomek" <tnto...@...> wrote: > > 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.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...@...()) > { > typeInfo = variab...@...(); > 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; > } >
To add, the following line expects a dataField to be provided (I have not) var property:String = _columns[event.columnIndex].dataField; but the code should not get there if its just a string.