2 Replies Latest reply on Jul 23, 2006 11:14 AM by TucsonJava

    DataGrid and nested properties

    TucsonJava Level 1
      As far as I know, DataGrid does not support the editing of a property if the property is a nested property. That is, if the DataGrid is bound to an ArrayCollection of OrderItems and an OrderItem has a propery called Product and Product has a property named description, then you cannot edit the description property from the DataGrid. I say that you cannot, hoping that someone will prove me wrong.

      I know that the property OrderItem.Product.description can be displayed OK by using a LabelFunction, however when editing that property, after losing focus a DataGridEvent is dispatched which is handled by itemEditorItemEditEndHandler in DataGrid.as. This method is always looking for the property name to update by getting the dataField property from the column. If you set the dataField property as "product.description" the method will throw an exception since it uses this syntax to try and set the new value for the property ...data[property] = newData; So no matter what you set the dataField property, once you end the editing the value, the itemEditorItemEditEndHandler will try to update the property and throw an exception.

      I am hoping someone from the Adobe team who is familiar with the DataGrid might address this issue and either say flatly "you can't edit nested properties" or provide some example of how it might be done.

      The alternative (which I would really like to avoid) would be to create dummy objects populated will all the values from the OrderItems and bind the DataGrid to that. Then, of course, xfer the values back to the original OrderItems after the user session is finished. Any suggestions would be appreciated and followed up on.
        • 1. Re: DataGrid and nested properties
          inlineblue Level 1
          As is, the DataGrid can't update nested properties. The only way I know to accomplish this is to provide a custom handler for the itemEditEnd event. First call event.preventDefault() to cancel the default behaviour. Then write your own routine to update the underlying data. At the end, make sure to call destroyItemEditor() to get rid of the editor.
          • 2. Re: DataGrid and nested properties
            TucsonJava Level 1
            Thanks for your suggestions. Yes, that seems to work well. For anyone interested, here is a sample of the handler for itemEditEnd event. I happen to only have one column that is being edited. If you had more, then it would require additional logic to determine which column was edited.

            private function endEdit(event:DataGridEvent):void{
            event.preventDefault(); // prevent default event handler from kicking in
            var index:int = DataGrid(event.currentTarget).selectedIndex; // get the index of the row being edited
            // the next 3 lines are very specific to the app I am working on
            var oi:OrderItem = OrderItem(orderDetails.getItemAt(index)); // get the data object bound to the row
            // notice the value being updated is a nested property
            oi.product.description = TextInput(event.currentTarget.itemEditorInstance).text; /// update the value w/new value
            orderDetails.setItemAt(oi, index); // put changed object back into row
            DataGrid(event.currentTarget).destroyItemEditor(); // remove the custom editor