0
votes

My issue is that when a user clicks a datagrid cell that has a combobox editor and then immediately clicks away from the cell, the text value in that cell disappears.

I have an itemEditEnd handler on the datagrid and it shows the value of the property I use as the editorDataField just fine. But the labelFunction (which gets called after the itemEditEnd handler) on that grid column sees it as zero.

Why aren't the labelFunction and item editor playing together nicely?

Here is the DataGridColumn:

<mx:DataGridColumn  
                                headerText="Field Name" 
                                dataField="attribId"
                                editorDataField="attributeId"
                                labelFunction="getFieldName">

Here is the Item editor

                            <mx:itemEditor>

                                <mx:Component>

                                    <mx:ComboBox 
                                        dataProvider="{this.outerDocument.lendersModel.fileAttributes}"
                                        creationComplete="{outerDocument.selectAttribute();}"
                                        labelField="fileAttribDesc"
                                        change="updateAttribute(event);"
                                        selectedIndex="-1">


                                        <mx:Script>
                                            <![CDATA[                                                   
                                                [Bindable]
                                                public var attributeId:int;
                                                private var fileDetailRecordType:String;

                                                override public function set data( value:Object ):void{
                                                    this.attributeId = value.attribId; // adding this line appears to be the fix. 
                                                    var category:String = value.category;

                                                    this.filterFileAttributes( category );
                                                }

                                                /** Change handler for combobox in Record Type column.  
                                                 */
                                                private function filterFileAttributes( recordType:String ):void{
                                                    this.fileDetailRecordType = recordType;

                                                    this.dataProvider.filterFunction = filterByRecordType;
                                                    this.dataProvider.refresh();
                                                }

                                                /** Filters the file attributes collection based on the record type. 
                                                 */
                                                private function filterByRecordType( item:Object ):String{
                                                    return item.category.match( this.fileDetailRecordType );
                                                }

                                                private function updateAttribute( event:* ):void{ 
                                                    attributeId = event.currentTarget.selectedItem.attribId;
                                                    this.outerDocument.selectedAttributeId = attributeId;
                                                }

                                            ]]>
                                        </mx:Script>

                                    </mx:ComboBox> 

                                </mx:Component>

                            </mx:itemEditor>

and here is the label function for the DataGridColumn.

        private function getFieldName( item:Object, dgc:DataGridColumn ):String{
            var fieldName:String = '';

            /* At this point the lendersModel.fileAttributes collection is
               filtered based on the record type. We need to remove the filter
               so we can search the entire collection, not just the filtered subset. */
            lendersModel.fileAttributes.filterFunction = refreshFilter;
            lendersModel.fileAttributes.refresh();

            for each( var attrib:FileAttributeDTO in lendersModel.fileAttributes ){
                if( attrib.attribId == item.attribId )
                    fieldName = attrib.fileAttribDesc;
            }

            return fieldName;
        }

And here is the code executed in the itemEditEndHandler for the Datagrid:

var rowCount:int = fieldsGridEmpty.selectedIndex; var attribCombo:ComboBox = ComboBox( fieldsGridEmpty.itemEditorInstance );

                if( rowCount != -1 && attribCombo.selectedItem != null )
                {                                                           
                    newFieldsDp[ rowCount ].fileAttribute.dataType = attribCombo.selectedItem.dataType;                                         
                    newFieldsDp[ rowCount ].fileAttribute.dataLength = attribCombo.selectedItem.dataLength; 
                    newFieldsDp[ rowCount ].fileAttribute.fileAttribDesc = attribCombo.selectedLabel;   
                    newFieldsDp[ rowCount ].dataLength = attribCombo.selectedItem.dataLength;       
                    newFieldsDp[ rowCount ].attribId = attribCombo.selectedItem.attribId;   
                }  

Now, the item edit handler shows a valid value for 'attribId':

newFieldsDp[ rowCount ].attribId = attribCombo.selectedItem.attribId;

However, the label function gets executed after this and the value for item.attribId is 0. And that's the reason 'fieldName' is an empty String, because there's no match.

1
Show some code; this is a bit confusiong. For example, are you using a labelFunction for the DataGrid column? Or for the Combobox? Are you using Spark components or Halo components?JeffryHouser
I've updated the post with the code. Unfortunately, I couldn't figure out how to get the mxml to go into code mode, sorry. But thank you for taking a look.fumeng
The open bracket/close bracket button will format the highlighted code.JeffryHouser
I'm testing a fix that appears to be working at this time and it makes sense. I add this line: this.attributeId = value.attribId; to the override public function set data method. The reason it makes sense is because this method will be invoked when a user clicks the combobox but doesn't make any changes. I'll add the line in the code of the original post.fumeng

1 Answers

0
votes

My fix mentioned in the comments seems to work. The underlying problem is that the editorDataField property was only set when the user interacted with the combobox.

I remedied that problem by setting it in the override public function set data() method. In this manner, as soon as a user touches it, it is set.