1 Reply Latest reply on Jan 15, 2011 8:07 PM by Gregory Lafrance

    Flex 4 Inline Item Editor Wiping Out Data

    Gregory Lafrance Level 6

      In this app that has an inline item editor, if you click on a location cell then press tab, the value in the location cell is wiped out.

       

      focusOut doesn't work, nor could I get this to work in DataGrid itemEditEnding etc.

       

      <?xml version="1.0"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Script>
          <![CDATA[
            import mx.collections.ArrayCollection;
            
            [Bindable] private var employees:ArrayCollection = new ArrayCollection([
              {fname: "Tom", lname: "Carson", location: "Los Angeles"},
              {fname: "Bob", lname: "Sandis", location: "Miami"},
              {fname: "Mary", lname: "Walart", location: "Los Angeles"},
              {fname: "Sam", lname: "Paulson", location: "New York"},
              {fname: "Frank", lname: "Trella", location: "Boston"},
              {fname: "Cindy", lname: "Garbeau", location: "Miami"}        
            ]);
            
            
          ]]>
        </fx:Script>
        <mx:DataGrid id="employeeDG" dataProvider="{employees}"
                     variableRowHeight="true"
                     editable="true">
          <mx:columns>
            <mx:DataGridColumn headerText="First Name" dataField="fname" width="100"/>
            <mx:DataGridColumn headerText="Last Name" dataField="lname" width="100"/>
            <mx:DataGridColumn headerText="Location" dataField="location" width="120"
                               editorDataField="location">
              <mx:itemEditor>
                <fx:Component>
                  <s:MXDataGridItemRenderer focusEnabled="true" height="22">
                    <fx:Script>
                      <![CDATA[
                        import mx.collections.ArrayList;
                        import mx.controls.Alert;
                          public function get location():String {
                            return locationList.selectedItem;
                          }
                      ]]>
                    </fx:Script>
                    <s:DropDownList id="locationList" top="5" left="5"
                                    prompt="{data.location}"
                                    initialize="locationList.dataProvider =
                                    new ArrayList(['Boston', 'Los Angeles', 'Miami', 'New York'])"/>
                  </s:MXDataGridItemRenderer>
                </fx:Component>
              </mx:itemEditor>
            </mx:DataGridColumn>      
          </mx:columns>
        </mx:DataGrid>
      </s:Application>
      
        • 1. Re: Flex 4 Inline Item Editor Wiping Out Data
          Gregory Lafrance Level 6

          The definition for the inline item editor needs this:

           

          selectedItem="{data.location}"

           

          instead of this:

           

          prompt="{data.location}"

           

          This is because the itemEditEnd event sets the newData property (deep within the code) to the value of selectedItem, so if you have only selected the cell and have not yet selected a value in the DropDownList, such as selecting the cell then immediately tabbing out, the value gets wiped out.