4 Replies Latest reply on Sep 26, 2009 6:22 AM by Gregory Lafrance

    DataGrid ComboBox itemRenderer/editor not updating dataProvider properly

    Gregory Lafrance Level 6

      I have a DataGrid with one column using a ComboBox as the itemRenderer. The column is editable but if you trace the dataProvider, the changes lag behind by one. So uncheck two row's ComboBox and the dataProvider only shows one row's data updated.

       

      Any ideas?

        • 1. Re: DataGrid ComboBox itemRenderer/editor not updating dataProvider properly
          Gregory Lafrance Level 6

          bump. Wondering if anyone has any ideas about this.

          • 2. Re: DataGrid ComboBox itemRenderer/editor not updating dataProvider properly
            JeffryHouser Level 4

            I guess I don't understand the question.

             

            A few things that are unclear to me:

             

            a) You usually check a CheckBox or possibly a RadioButton; you don't check a ComboBox

            b) What does "changes lag behind by one" mean?

             

            I'm pretty sure that dataProvider won't be updated until you leave the row, although I'm not sure if that helps answer the question.

            1 person found this helpful
            • 3. Re: DataGrid ComboBox itemRenderer/editor not updating dataProvider properly
              drillnaut Level 1

              Not really sure if this helps but here is an idea.  I remember reading somewhere that the number of rows in a DG is always plus one of however many rows of data you have.  Something about how the first row , the column label row is considered row 0.  So for 35 rows of data , the dg may actually see 36 rows.  So if the 35 rows of raw data you provided are "selected" , then you deselect one , it will see 35 rows of data selected because it is counting the column row.  But then again , this is an uneducated hunch.

               

              Sincerely ,

                D

              • 4. Re: DataGrid ComboBox itemRenderer/editor not updating dataProvider properly
                Gregory Lafrance Level 6

                Yep, its a CheckBox, too early in the morning.

                 

                Another component (DataGrid) will be filtered depending on what rows in the ADG have their CheckBox checked, so leaving the row may be too late.

                 

                Here is the code I have so far. In the itemEditEnd event handler I'm trying to set the field in the dataProvider manually, but it causes an infinite loop. preventDefault and stopImmediatePropagation don't help.

                 

                ----- CheckBoxRenderer.mxml -----

                 

                <?xml version="1.0"?>
                <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
                  <mx:Script>
                    <![CDATA[
                      import mx.controls.CheckBox;
                     
                      [Bindable] public var newSelected:Boolean;
                    ]]>
                  </mx:Script>
                  <mx:CheckBox id="selectedChbx" selected="{data.FLAG}"/>
                </mx:VBox>

                 

                ----- mainapp.mxml -----

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                  <mx:Script>
                    <![CDATA[
                      import mx.events.AdvancedDataGridEvent;
                      import mx.collections.ArrayCollection;
                      import mx.controls.CheckBox;
                     
                      [Bindable] private var transactions:ArrayCollection = new ArrayCollection([
                        {orderID: "33725", theirOrderNumber: "10170", name: "Bob Smith", SKUs: "21", PICKS: "50", FLAG: "true"},
                        {orderID: "33729", theirOrderNumber: "10172", name: "Mary Wilson", SKUs: "3", PICKS: "6", FLAG: "true"},
                        {orderID: "33730", theirOrderNumber: "10176", name: "Fred Carson", SKUs: "1", PICKS: "2", FLAG: "true"},
                        {orderID: "33731", theirOrderNumber: "10177", name: "Morten Hills", SKUs: "5", PICKS: "16", FLAG: "true"},
                        {orderID: "33732", theirOrderNumber: "10178", name: "Bill Trundy", SKUs: "5", PICKS: "34", FLAG: "true"},
                        {orderID: "33734", theirOrderNumber: "10179", name: "Ocean Boat Supply", SKUs: "8", PICKS: "19", FLAG: "true"},
                        {orderID: "33736", theirOrderNumber: "10180", name: "Janet Aberdine", SKUs: "5", PICKS: "18", FLAG: "true"},
                        {orderID: "33737", theirOrderNumber: "10181", name: "Kim Restine", SKUs: "2", PICKS: "6", FLAG: "true"},
                        {orderID: "33738", theirOrderNumber: "10182", name: "Thomas Overby", SKUs: "5", PICKS: "12", FLAG: "true"}
                      ]);

                      public function handleGridChanged(evt:AdvancedDataGridEvent):void{
                        var newData:Boolean = CheckBoxRenderer(evt.currentTarget.itemEditorInstance).newSelected;
                        trace(evt.rowIndex);
                        var obj:Object = transactions.getItemAt(evt.rowIndex);
                        trace("BEFORE: " + obj.FLAG);
                        obj.FLAG = newData;
                        trace("AFTER: " + obj.FLAG);
                        transactions.setItemAt(obj, evt.rowIndex);
                        return;
                        evt.preventDefault();
                        evt.stopImmediatePropagation();
                       
                //        for each(var item:Object in transactions){
                          //trace(item.FLAG);
                //        }
                      }
                    ]]>
                  </mx:Script>
                  <mx:Label fontSize="12" text="Bulk Print / Pull - Step 1"/>
                  <mx:HBox>
                    <mx:AdvancedDataGrid id="dgTransactions" dataProvider="{transactions}"
                      fontSize="12" editable="true" sortableColumns="true" height="500"
                      width="100%" itemEditEnd="handleGridChanged(event);">
                        <mx:columns>
                          <mx:AdvancedDataGridColumn dataField="orderID" headerText="WMSOID" width="100"
                            editable="false" textAlign="center"/>
                          <mx:AdvancedDataGridColumn dataField="theirOrderNumber" headerText="Order #"
                            textAlign="center" width="130" editable="false"/>
                          <mx:AdvancedDataGridColumn dataField="name" headerText="Customer"
                            width="125" textAlign="left" editable="false"/>
                          <mx:AdvancedDataGridColumn dataField="SKUs" headerText="SKU's"
                            width="75" textAlign="right" editable="false"/>
                          <mx:AdvancedDataGridColumn dataField="PICKS" headerText="Picks"
                            width="75" textAlign="right" editable="false"/>    
                          <mx:AdvancedDataGridColumn dataField="FLAG" headerText="I" width="20" textAlign="center"
                            editable="true" rendererIsEditor="true" editorDataField="newSelected"
                            itemRenderer="CheckBoxRenderer"/>
                        </mx:columns>
                    </mx:AdvancedDataGrid>
                    <mx:DataGrid>
                       
                    </mx:DataGrid>
                  </mx:HBox>
                </mx:Application>