4 Replies Latest reply on Oct 12, 2010 10:00 AM by DazMMT

    itemFocusOutHandler with editable data grid selected item issue

    DazMMT

       

      Hi All, I’m relatively new to Flex and have an issue that is causing a lot of frustration. I’m sure that the solution is string me in the face but I just can’t see the wood for the trees.

       

       

       

      OK, I’m trying to achieve a data grid that is populated with data based on a one-to-many relationship between people and courses with a join to show people that do not have course assigned and then assign these by date if required.

       

       

       

      This is then action by itemFocusOutHandler where the database is then updated with the data grid selected item.

       

       

       

      The issue: When you move away from the updated cell the event is trigger and the database is updated with the new selected row and not the one moved from. I was expecting the updated to trigger before the selected item is change but this does not seem to be the case.

       

       

       

      Example

       

      Course.jpg

       

       

       

      Course added to John on the 24th

       

       

       

      On tab away to Jason the selected item changes and Jason is added to the database with no entry. Alsom If I then go back to John from Jason the database will be updated with the data for John

       

       

       

      Database view:

       

      Table_IDCourseHeaderDatePerson_IDHeader 4
      1
      28/10/20102

       

       

       

      Where Person equals

       

       

       

      Table_IDFirstLast
      1JohnSmith
      2JasonHolmes

       

       

       

      Any help you are willing to provide will be very much appreciated.

       

       

       

      Kind regards, Darren.

       

       

       

       

      And the code (I have tried to simplify this where possible):

       

       

       

       

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

       

      <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" minWidth="955" minHeight="600"

       

                           xmlns:register="services.Course.*">

       

       

       

            <fx:Script>

       

                  <![CDATA[

       

                       

       

                        import mx.controls.DateField;

       

                        import mx.controls.Text;

       

                        import mx.data.ChangeObject;

       

                        import mx.events.CalendarLayoutChangeEvent;

       

                        import mx.events.CollectionEvent;

       

                        import mx.events.DataGridEvent;

       

                        import mx.events.FlexEvent;

       

                        import mx.events.ListEvent;

       

                       

       

           

       

           

       

                        protected function dC1_changeHandler(event:CalendarLayoutChangeEvent):void

       

                        {

       

                              var dforQ:String = DateField.dateToString(dC1.selectedDate, "DD/MM/YYYY" );

       

                              var SD189:String = dforQ;

       

                              gateCbyDResult.token = csr.gateCbyD(SD189);

       

                             

       

                        }

       

       

       

                        protected function dataGrid_itemFocusOutHandler(event:DataGridEvent):void

       

                        {

       

                              var dateSQLDate:String = DateField.dateToString(dC1.selectedDate, "DD/MM/YYYY" );

       

                              var entrydate:String = dateSQLDate;

                              saveNewResult.token = csr.saveNew(dataGrid.selectedItem.course,entrydate,dataGrid.selectedItem.empid);

                        }

       

                       

                  ]]>

            </fx:Script>

            <fx:Declarations>

                  <csr:Csr id="csr" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

                  <s:CallResponder id="saveNewResult"/>

                  <s:CallResponder id="gateCbyDResult"/>

            </fx:Declarations>

       

                  <mx:DataGrid x="103" y="252"

                              id="dataGrid"

                              dataProvider="{gateCbyDResult.lastResult}"

                              verticalScrollPolicy = "off"

                              rowCount="{dataGrid.dataProvider.length}"

                              editable="true"

                              itemEditEnd="dataGrid_itemFocusOutHandler(event)">

                             

                  <mx:columns>

                        <mx:DataGridColumn headerText="Last" dataField="lastName" editable="false"/>

                        <mx:DataGridColumn headerText="First" dataField="firstName" editable="false"/>                 

                        <mx:DataGridColumn id="courseInput" headerText="Course" dataField="course" editable="true"/>

                  </mx:columns>

            </mx:DataGrid>

            <mx:DateChooser id="dC1" change="dC1_changeHandler(event)" x="102" y="38" />

       

      </s:Application>

       

      Thanks again...