12 Replies Latest reply on Feb 20, 2011 11:13 PM by vineet osho

    Problem In Rendreing combobox in DataGrid

    vineet osho Level 1

      Hi

           i am making a datagrid in which i am rendring a combobox and data provider of my data grid is xml type.The real trick is getting the XML file to be updated when changes to the itemRenderer(combobox) occurred.i am unable to reflect the changes on itemRendrer(combox) from updated xml dynamically.

      can any body guides me how to implement that feature.

       

      Thanks and regards

         Vineet Osho 

        • 2. Re: Problem In Rendreing combobox in DataGrid
          vineet osho Level 1

          Hi Miguel

                          thanks for ur quick reply.but this is not i what i want.i already used these stuff.but i am facing problem how to update my data in combox dynamically when my xml changes.

          if u r not getting my point than may i send source code of my demo application?

           

           

          Thanks And Regars

            Vineet Shrama

          • 3. Re: Problem In Rendreing combobox in DataGrid
            G1Z

            Hi Vineet,

             

            do you want to update the XML Dynamically or the Datagrid's Combo Box ? I did not get your query properly.

             

            Thanks,

            Jeevan

            • 4. Re: Problem In Rendreing combobox in DataGrid
              miguel8312 Level 3

              yes please send me the source code. I will be more then willing to help you get this resolved.

              • 5. Re: Problem In Rendreing combobox in DataGrid
                vineet osho Level 1

                hi

                     i am attaching the code.it will updating the xml.on runtime i just want how to update the combobox when call the service again.for this i need id of combobx.so my problem is that i cant access my rendrer(combobox) from this.

                <root>
                <data>
                  <expirationdate>10/13/2010</expirationdate>
                  <ldfID>4292</ldfID>
                  <effectivedate>10/13/2009</effectivedate>
                  <customerpolicyID>1018</customerpolicyID>
                  <priorcarriername>m</priorcarriername>
                  <lastupdatetimestamp>02/11/2011</lastupdatetimestamp>
                  <lossevaluationdate>10/13/2006</lossevaluationdate>
                  <lastupdateuserID>13</lastupdateuserID>
                  <noopen>no</noopen>
                </data>
                <data>
                  <expirationdate>10/13/2009</expirationdate>
                  <ldfID>4293</ldfID>
                  <effectivedate>10/13/2008</effectivedate>
                  <customerpolicyID>1018</customerpolicyID>
                  <priorcarriername>m</priorcarriername>
                  <lastupdatetimestamp>02/11/2011</lastupdatetimestamp>
                  <lossevaluationdate>10/13/2006</lossevaluationdate>
                  <lastupdateuserID>13</lastupdateuserID>
                  <noopen>yes</noopen>
                </data>
                <data>
                  <expirationdate>10/13/2008</expirationdate>
                  <ldfID>4294</ldfID>
                  <effectivedate>10/13/2007</effectivedate>
                  <customerpolicyID>1018</customerpolicyID>
                  <priorcarriername>m</priorcarriername>
                  <lastupdatetimestamp>02/11/2011</lastupdatetimestamp>
                  <lossevaluationdate>10/13/2006</lossevaluationdate>
                  <lastupdateuserID>13</lastupdateuserID>
                  <noopen>yes</noopen>
                </data>
                <data>
                  <expirationdate>10/13/2007</expirationdate>
                  <ldfID>4295</ldfID>
                  <effectivedate>10/13/2006</effectivedate>
                  <customerpolicyID>1018</customerpolicyID>
                  <priorcarriername>m</priorcarriername>
                  <lastupdatetimestamp>02/11/2011</lastupdatetimestamp>
                  <lossevaluationdate>10/13/2006</lossevaluationdate>
                  <lastupdateuserID>13</lastupdateuserID>
                  <noopen>no</noopen>
                </data>
                <data>
                  <expirationdate>10/13/2006</expirationdate>
                  <ldfID>4296</ldfID>
                  <effectivedate>10/13/2005</effectivedate>
                  <customerpolicyID>1018</customerpolicyID>
                  <priorcarriername>m</priorcarriername>
                  <lastupdatetimestamp>02/11/2011</lastupdatetimestamp>
                  <lossevaluationdate>10/13/2006</lossevaluationdate>
                  <lastupdateuserID>13</lastupdateuserID>
                  <noopen>yes</noopen>
                </data>
                </root>
                

                 

                <?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"
                               creationComplete="init()" xmlns:local="*">
                        <mx:DataGrid id="dgTest" editable="true"  y = "30"
                            dataProvider = "{gridData.data}" width = "100%">
                            <mx:columns>
                                <mx:DataGridColumn dataField = "lastupdateuserID" width = "80" headerText = "first"
                                    sortable="false">
                                    <mx:itemRenderer>
                                        <fx:Component>
                                            <mx:TextInput  width = "100"/>
                                        </fx:Component>
                                    </mx:itemRenderer>
                                </mx:DataGridColumn>
                                <mx:DataGridColumn  width = "80" headerText = "second" editable="false">
                                    <mx:itemRenderer>
                                        <fx:Component>
                                            <mx:Box>
                                                <fx:Script>
                                                    <![CDATA[
                                                        import mx.controls.Alert;
                                                        public function populateArray(str:String):void{
                                                            outerDocument.arrTemp[outerDocument.dgTest.selectedIndex] = str;
                                                            outerDocument.xmlGenrate();
                                                        }
                                                        public function onCreate():void{
                                                            cmbChange.dataProvider = outerDocument.xml.node;
                                                        }
                                                    ]]>
                                                </fx:Script>
                                                <mx:ComboBox  id="cmbChange" height="50%" width="50%"
                                                    creationComplete="onCreate()"
                                                      change="populateArray(cmbChange.selectedItem+'')">
                                                </mx:ComboBox>
                                            </mx:Box>
                                        </fx:Component>
                                    </mx:itemRenderer>
                                </mx:DataGridColumn>
                            </mx:columns>
                        </mx:DataGrid> 
                    <s:Button id="btnSave" label="Save" click="test()"/>
                    <fx:Declarations>
                        <s:HTTPService id="httpTest" resultFormat="e4x" result="resulthandler(event)" fault=";"/>
                    </fx:Declarations>
                    <fx:Script>
                        <![CDATA[
                            import mx.collections.ArrayCollection;
                            import mx.events.ChildExistenceChangedEvent;
                            import mx.controls.Alert;
                            import mx.controls.CheckBox;
                            import mx.events.ListEvent;
                            import mx.rpc.events.ResultEvent;
                            import mx.utils.ObjectUtil;
                            import spark.components.ComboBox;
                            import spark.components.TextInput;
                            import spark.components.supportClasses.ItemRenderer;
                            [Bindable]
                            public var xml:XML = new XML(<root>
                                                    <node>yes</node>
                                                    <node>no</node>
                                                    </root>);
                            [Bindable]
                            public var arrTemp:Array =[];
                            private var req_XML:XML;
                            [Bindable]
                            private var gridData:XML;
                            private function endHandler(ev:DataEvent):void{
                                Alert.show("Hello");
                            }
                            public function xmlGenrate():void{
                                var obj:XML = gridData;
                                var temp:XMLList = obj.data.children();
                                    var i :int = 0;
                                    for(var a:int=0;a < temp.length(); a++){
                                        var str1:String = temp[a].localName();
                                            var str:XML=createXml(i);
                                            if(str1 == 'noopen'){
                                                delete gridData.data.noopen[i];
                                                gridData.data[i].insertChildAfter(gridData.data.lastupdateuserID[i],str);
                                                if(i==gridData.data.length()-1){
                                                    return ;
                                                }
                                                else{
                                                    i++;
                                                }
                                            }
                                            if(obj.data[i].toString().indexOf('noopen')==-1){
                                                gridData.data[i].insertChildAfter(gridData.data.lastupdateuserID[i],str);
                                                if(i==gridData.data.length()-1){
                                                    return ;
                                                }
                                                else{
                                                    i++;
                                                }
                                            }
                                    }
                            }
                            private function createXml(i:int):XML{
                                if(arrTemp[i] == 'null'){
                                    req_XML = <noopen></noopen>;
                                }
                                else{
                                    req_XML = <noopen>{arrTemp[i].toString()}</noopen>;
                                }
                                return req_XML;
                            }
                            private function init():void{
                                httpTest.url = 'data.xml';
                                httpTest.send();
                            }
                            private function resulthandler(ev:ResultEvent):void{
                                gridData = ev.result as XML;
                                for(var i:int =0;i<gridData.data.length();i++){
                                    arrTemp[i] = gridData.data[i].noopen;
                                }
                            }
                            public function test():void{
                                Alert.show(gridData.data+'');
                            }
                        ]]>
                    </fx:Script>
                </s:Application>

                • 6. Re: Problem In Rendreing combobox in DataGrid
                  miguel8312 Level 3

                  vineet

                  I guess I'm missing something what is the expected outcome. I hit yes what should happen? when i hit no what should happen? i guess i still dont follow. I do see that the xml its not updating anything ??? can explain a little better?

                  Thanks

                  Miguel

                  • 7. Re: Problem In Rendreing combobox in DataGrid
                    vineet osho Level 1

                    Hi Miguel

                                    plz run this code

                    and choose 'yes or no' from any combo box rendred in grid and press save button.then plz check noopen node u will getupdated xml at respective node.

                    this is working properly but the main problem is that when i again call the service it will not refelct because i cant rendred my data on combox again(first time i used creation complete event).

                     

                     

                    <?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"
                                   creationComplete="init()" xmlns:local="*">
                            <mx:DataGrid id="dgTest" editable="true"  y = "30"
                                dataProvider = "{gridData.data}" width = "100%">
                                <mx:columns>
                                    <mx:DataGridColumn dataField = "lastupdateuserID" width = "80" headerText = "first"
                                        sortable="false">
                                        <mx:itemRenderer>
                                            <fx:Component>
                                                <mx:TextInput  width = "100"/>
                                            </fx:Component>
                                        </mx:itemRenderer>
                                    </mx:DataGridColumn>
                                    <mx:DataGridColumn  width = "80" headerText = "second" editable="false">
                                        <mx:itemRenderer>
                                            <fx:Component>
                                                <mx:Box>
                                                    <fx:Script>
                                                        <![CDATA[
                                                            import mx.controls.Alert;
                                                            public function populateArray(str:String):void{
                                                                outerDocument.arrTemp[outerDocument.dgTest.selectedIndex] = str;
                                                                outerDocument.xmlGenrate();
                                                            }
                                                            public function onCreate():void{
                                                                cmbChange.selectedItem=data.noopen.toString();
                                                            } 
                                                        ]]>
                                                    </fx:Script>
                                                    <mx:ComboBox  id="cmbChange" height="50%"
                                                                  width="50%" creationComplete="onCreate()"
                                                                  change="populateArray(cmbChange.selectedItem+'')"
                                                                  dataProvider="{outerDocument.xml.node}">
                                                    </mx:ComboBox>
                                                </mx:Box>
                                            </fx:Component>
                                        </mx:itemRenderer>
                                    </mx:DataGridColumn>
                                </mx:columns>
                            </mx:DataGrid> 
                        <s:Button id="btnSave" label="Save" click="test()"/>
                        <fx:Declarations>
                            <s:HTTPService id="httpTest" resultFormat="e4x" result="resulthandler(event)" fault=";"/>
                        </fx:Declarations>
                        <fx:Script>
                            <![CDATA[
                                import mx.collections.ArrayCollection;
                                import mx.events.ChildExistenceChangedEvent;
                                import mx.controls.Alert;
                                import mx.controls.CheckBox;
                                import mx.events.ListEvent;
                                import mx.rpc.events.ResultEvent;
                                import mx.utils.ObjectUtil;
                                import spark.components.ComboBox;
                                import spark.components.TextInput;
                                import spark.components.supportClasses.ItemRenderer;
                                [Bindable]
                                public var xml:XML = new XML(<root>
                                                        <node>yes</node>
                                                        <node>no</node>
                                                        </root>);
                                [Bindable]
                                public var arrTemp:Array =[];
                                private var req_XML:XML;
                                [Bindable]
                                private var gridData:XML;
                                public function xmlGenrate():void{
                                    var obj:XML = gridData;
                                    var temp:XMLList = obj.data.children();
                                        var i :int = 0;
                                        for(var a:int=0;a < temp.length(); a++){
                                            var str1:String = temp[a].localName();
                                                var str:XML=createXml(i);
                                                if(str1 == 'noopen'){
                                                    delete gridData.data.noopen[i];
                                                    gridData.data[i].insertChildAfter(gridData.data.lastupdateuserID[i],str);
                                                    if(i==gridData.data.length()-1){
                                                        return ;
                                                    }
                                                    else{
                                                        i++;
                                                    }
                                                }
                                                if(obj.data[i].toString().indexOf('noopen')==-1){
                                                    gridData.data[i].insertChildAfter(gridData.data.lastupdateuserID[i],str);
                                                    if(i==gridData.data.length()-1){
                                                        return ;
                                                    }
                                                    else{
                                                        i++;
                                                    }
                                                }
                                        }
                                }
                                private function createXml(i:int):XML{
                                    if(arrTemp[i] == 'null'){
                                        req_XML = <noopen></noopen>;
                                    }
                                    else{
                                        req_XML = <noopen>{arrTemp[i].toString()}</noopen>;
                                    }
                                    return req_XML;
                                }
                                private function init():void{
                                    httpTest.url = 'data.xml';
                                    httpTest.send();
                                }
                                private function resulthandler(ev:ResultEvent):void{
                                    gridData = ev.result as XML;
                                    for(var i:int =0;i<gridData.data.length();i++){
                                        arrTemp[i] = gridData.data[i].noopen;
                                    }
                                }
                                public function test():void{
                                    Alert.show(gridData.data+'');
                                }
                            ]]>
                        </fx:Script>
                    </s:Application>

                    • 8. Re: Problem In Rendreing combobox in DataGrid
                      BhaskerChari Level 4

                      Hi Vineet,

                       

                      If my understanding is correct you are able to update the xml at runtime when you make changes in the ComboBox and see the xml updated but when you cal the service again you are not able to see the updated xml but the old xml.

                       

                      However this is expected as you are not actually updating the xml file that resides on your server..but you are updating only the xml stored in your gridData variable and not the actual xml ... and as the xml file contents are still the same and when you call the service again the xml file is again reloaded which contains the old original contents and not updated one...so it shows the previous selections in your ComboBox.

                       

                      Hope you understand what I am saying..In order to get the updated xml the next time you call the service you need to overwrite the updated xml content which is the stored in the gridData variable in the data.xml file when you make changes and click Save button..Just updating only in the gridData variable is not enough.

                       

                       

                      Thanks,

                      Bhasker

                      1 person found this helpful
                      • 9. Re: Problem In Rendreing combobox in DataGrid
                        vineet osho Level 1

                        Thanks bhasker nice to see u again.u got the problem but i am explaing the exact scenario.i am calling a function name onCreate on creation complete of combobox.in which i am setting the selected item of that combobox.but when i agian call the service then that  method would not fired again because combox in grid is already created.so selected item remaining old in combox.hope u got my point.i need some clue how to reset my xml in selected item of respective combo box for which i required id of combobox that is looking impossible for me.

                        So please help me out from this problem.

                         

                        Regards

                        Vineet Osho

                        • 10. Re: Problem In Rendreing combobox in DataGrid
                          miguel8312 Level 3

                          have you tried doing this before everytime the call to get the xml happens

                           

                          dgtest.dataProvider.removeAll();

                          I think I follow what you are saying now, but this should do it. everytime you call your function and you parse the xml remove the dataprovider and then add it back post back and tel me if that worked.

                          Miguel

                          • 11. Re: Problem In Rendreing combobox in DataGrid
                            BhaskerChari Level 4

                            Hi Vineet,

                             

                            Instead of using the onCreate function in creationComplete of the ComboBox you just override the set data() method in the ComboBox script tag..that will do the trick..

                             

                            override public function set data(value:Object):void
                            {
                                 super.data = value;
                                 if(value != null)
                                 {
                                      cmbChange.selectedItem = value.noopen.toString();    
                                 }

                            }

                             

                            You can now remove the onCreate function....

                             

                             

                            ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ ---------------------

                             

                             

                             

                            <mx:DataGridColumn  width = "80" headerText = "second" editable="false">
                                                <mx:itemRenderer>
                                                    <fx:Component>
                                                        <mx:Box>
                                                            <fx:Script>
                                                                <![CDATA[
                                                                    import mx.controls.Alert;
                                                                    public function populateArray(str:String):void{
                                                                        outerDocument.arrTemp[outerDocument.dgTest.selectedIndex] = str;
                                                                        outerDocument.xmlGenrate();
                                                                    }                                     

                                                                   

                                                                    override public function set data(value:Object):void
                                                                    {
                                                                         super.data = value;
                                                                         if(value != null)
                                                                         {
                                                                              cmbChange.selectedItem = value.noopen.toString();    
                                                                         }

                                                                    }    

                                                                ]]>
                                                            </fx:Script>
                                                            <mx:ComboBox  id="cmbChange" height="50%"
                                                                          width="50%" creationComplete="onCreate()"
                                                                          change="populateArray(cmbChange.selectedItem+'')"
                                                                          dataProvider="{outerDocument.xml.node}">
                                                            </mx:ComboBox>
                                                        </mx:Box>
                                                    </fx:Component>
                                                </mx:itemRenderer>
                                            </mx:DataGridColumn>

                             

                             

                            Thanks,

                            Bhasker

                             

                            Message was edited by: BhaskerChari

                            • 12. Re: Problem In Rendreing combobox in DataGrid
                              vineet osho Level 1

                              Thanks a ton Bhasker it works for me.

                              Miguel Thanks for your helpful replys