9 Replies Latest reply on May 18, 2011 5:28 AM by Nishant Jha28

    Two datagrids getting data from one PHP data service

    python79

      Hi,

      on my main screen I have got an invisible datagrid that receives data from a PHP data service via a MySQL database table. Every row of this datagrid contains data that is used by a visible form to fill its fields. So by default the first row of the datagrid is selected (within this form are buttons: forward and backward to go through all the other entries in the datagrid, but this is just side information).

       

      On my main screen I have also got a navigation bar within which one button opens a titlewindow (I am working with mx-components only, so no spark). This titlewindow contains another datagrid which gets data from the same database table (using the same data service). As soon as this datagrid received data, the selection in my datagrid on the main screen disappears (only the selection, not the data) and so all the information in the form also disappears (leaving empty fields).

       

      My wish is, that the selection in the datagrid on the main screen does not disappear. How can I achieve this?

       

      I tried to narrow down the problem and the only thing I can say is that the problem has something to do with the data service used by the datagrid in the titlewindow. Without this data service the selection in the datagrid on the main screen does not disappear.

       

      Your help is very much appreciated!

       

      Padraig

        • 1. Re: Two datagrids getting data from one PHP data service
          Flexicious Level 1

          It could be a number of things that could cause the master datagrid to loose its selection. Without looking at the source or being able to debug locally, its quite hard to say, but what you could do is to wire up a change event handler to the first data grid, and put a breakpoint in it. Then when the break point is hit, look at the call stack and see what triggered that change event. Should get you an idea of what the cause is and then be able to stop it from wiping out your selection.

           

           

          ===============================

          Flexicious - The MUST Have Flex DataGrid

          http://www.flexicious.com/

          • 2. Re: Two datagrids getting data from one PHP data service
            python79 Level 1

            I can't figure out, which or if any event is fired when the deselection happens. The datagrid on the mainscreen has eventlisteners for change and collectionchange-events, but none of them is fired when the deselection happens. This guy had the same problem: http://forums.adobe.com/message/3118309#3118309

            • 3. Re: Two datagrids getting data from one PHP data service
              Level 2

              Show some code also why are u doing this and not databinding  How many rows are we talking about

              • 4. Re: Two datagrids getting data from one PHP data service
                Level 2

                Iterate thru a collection with a counter and current pointer ...  Not a hidden grid then wondering why it loses it lunch.

                • 5. Re: Two datagrids getting data from one PHP data service
                  Flexicious Level 1

                  Are you using the Flex DataGrid or the AdvancedDataGrid?

                   

                  ===============================

                  Flexicious - The MUST Have Flex DataGrid

                  http://www.flexicious.com/

                  • 6. Re: Two datagrids getting data from one PHP data service
                    python79 Level 1

                    "why are u doing this and not databinding  " --> guided me in the right direction. Since both datagrids used the same data service operation to receive data, I duplicated this operation at first in my PHP script and afterwards in the Data/Services panel. Now every datagrid has its own data service operation and the selection does not disappear anymore - problem solved

                     

                    By the way, I am using "normal" datagrids and two different queries are necessary, because different parameters are necessary for SQL statements in PHP.

                     

                    Still I am not quite sure, why this happens. Both datagrids are in different components, so each service operation (even if it's the same operation, as originally used by me) has its own callresponder which I thought is responsible for holding the returned data and thus also selections.

                    • 7. Re: Two datagrids getting data from one PHP data service
                      Level 2

                      hope you are all set if not let us know thx

                      • 8. Re: Two datagrids getting data from one PHP data service
                        python79 Level 1

                        Thanks to all who contributed to this thread!

                        • 9. Re: Two datagrids getting data from one PHP data service
                          Nishant Jha28 Level 2

                          I have created a sample use this logic if you need...

                           

                          <?xml version="1.0" encoding="utf-8"?>
                          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                              layout="vertical" creationComplete="cc()">
                             <mx:Script>
                             <![CDATA[
                                 import mx.events.FlexEvent;
                                 import mx.events.ListEvent;
                                import mx.collections.*;
                                private var DGArray:Array = [
                                   {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99},
                                   {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}];
                                  
                                [Bindable]
                                public var initDG:ArrayCollection;
                               
                                [Bindable]
                                private var newArrayC:ArrayCollection = new ArrayCollection([
                                   {Artist:'Pavement2', Album:'Slanted and Enchanted2', Price:11.99},
                                   {Artist:'Pavement2', Album:'Brighten the Corners2', Price:11.99}]);
                               
                                public function initData():void {
                                   initDG = new ArrayCollection(DGArray);
                                   myGrid.dataProvider = initDG;
                                }
                               
                                public function cc():void
                                {
                                      //ti1.text = initDG.getItemAt(0).Album;   
                                      //ti2.text = initDG.getItemAt(0).Price;       
                                }
                               
                                private function clicked():void
                                {
                                      myGrid.dataProvider = newArrayC;
                                }
                               
                                private function selectThis(event:ListEvent):void
                                {
                                      //ti1.text = (myGrid.dataProvider as ArrayCollection).getItemAt(event.rowIndex).Album;
                                      //ti2.text = (myGrid.dataProvider as ArrayCollection).getItemAt(event.rowIndex).Price;                 
                                }
                               
                               private function updateCompleted():void
                                {
                                     if(myGrid.selectedIndex < 0)
                                     {
                                         myGrid.selectedIndex = 0;
                                     }   
                                }

                               
                             ]]>
                             </mx:Script>

                           

                             <mx:DataGrid id="myGrid" width="350" height="200" preinitialize="initData()" itemClick="selectThis(event)"
                                updateComplete="updateCompleted()">
                                <mx:columns>
                                   <mx:DataGridColumn dataField="Album" />
                                   <mx:DataGridColumn dataField="Price" />
                                </mx:columns>
                             </mx:DataGrid>
                            
                             <mx:TextInput id="ti1" text="{(myGrid.dataProvider as ArrayCollection).getItemAt(myGrid.selectedIndex).Album}"/>
                             <mx:TextInput id="ti2" text="{(myGrid.dataProvider as ArrayCollection).getItemAt(myGrid.selectedIndex).Price}"/>
                            
                             <mx:Button label="Click" click="clicked()"/>
                            
                          </mx:Application>

                           

                           

                          Though this is not appropriate you should be using the itemClick and creationComplete Logic to achieve this. If you do that you will have to manually dispatch itemClick event on the dataGrid in the UpdateComplete or just set al the fields in the input.

                           

                          I have highlighted the part that constitutes of the important logic. Note that the selectedIndex becomes -1 when the dataProvider changes.