6 Replies Latest reply on Jun 21, 2010 5:49 AM by quebequiano

    populate a DataGrid everytime i show it

    quebequiano

      Hi!

       

      I'm developing a Flex/Java/BlazeDS application.

       

      I want to populate a dataGrid with a remote call over Java everytime I show it (Refresh the dataGrid).

       

      I tried to do it with the show() event of the dataGrid, but it doesn't work. I tried with the show event of the Canvas which contains the the dataGrid, but it doesn't refresh the dataGrid if i change the state and i come back to the state where the dataGrid is.

       

      What's the best way to do this?

       

      Thanks

       

      Angel

        • 1. Re: populate a DataGrid everytime i show it
          JeffryHouser Level 4

          What are you trying to do on the show event of the DataGrid and/or Canvas? Are you making another remote call?  Or something else?

           

          How are you showing and/or hiding the DataGrid?

          • 2. Re: populate a DataGrid everytime i show it
            quebequiano Level 1

            I get the data from a MySql DataBase.

             

            See the following image, I want to refresh the dataGrid everytime is shown. If you click over the row, the state is changed and you ger more information about the row (changing the current state). I want to refresh the dataGrid if you come back from this state, or if you click on the link button, or if you click in the tabNavigator and the dataGrid is shown (The idea is sample: refresh the dataGrid everytime that is shown).

             

            I tried with addToStage... but it only works when you change the state, if i go to "Contacto" Tab and i come back, it doesn't refresh the dataGrid.

             

            captura.JPG

            • 3. Re: populate a DataGrid everytime i show it
              JeffryHouser Level 4

              quebequiano wrote:

               

              I get the data from a MySql DataBase


              From your original request it was not clear how you were updating  the data.

               

              How?  When?  What is your code?  Are you calling a remoteObject?  If so, in what event?

               

              It looks like you're using a tabNaviator is that correct?  You should be able to perform the new remote service call in an event listener for the change event of the tabNavigator.

              • 4. Re: populate a DataGrid everytime i show it
                vu.tuan.anh Level 1

                Hi,

                 

                If your data provider is ArrayCollection, try to refresh it e.g. arraycollection.refresh()

                 

                Regards,

                Anh

                • 5. Re: populate a DataGrid everytime i show it
                  BhaskerChari Level 4

                  Hi quebequiano,

                   

                  Add a change  event for your TabNavigator and send a remote call every time you change the tab from another tab into the tab which you have datagrid.

                   

                  I mean track the change event and check if the current selected index of the TabNavgator is equal to the index in which your DataGrid is present then send a remote call to your Server to refresh or get the fresh data.

                   

                   

                  Thanks,

                  Bhasker Chari

                  1 person found this helpful
                  • 6. Re: populate a DataGrid everytime i show it
                    quebequiano Level 1

                    I call a Java method by a remoteObject, then I get the information from mySql.

                     

                    The problem I have is that every time you click on a row of the dataGrid the state change and the dataGrid is hidden, then you get more information about the selected row.

                     

                    The solutions you proposed are good, but partial solutions. Because if the dataGrid is hidden (because we're not in the state where the dataGrid is shown) it shouldn't be refresh when you go to another tab (from the tabNavigator) and you come back to this tab.

                     

                    I have an idea of a good solution:

                     

                    Combine show event, with enterState event, and make a call over a function whose first step will be to check the state of the tab.

                     

                    something like this:

                     

                    Put the following properties on the container where the dataGrid is: (In this case: VBox)

                     

                             creationComplete="getFacturas()"
                             show="mostrarLista()"
                             enterState="mostrarLista()

                     

                    and then and the following function:

                     

                     

                     

                                public function showList():void
                                {
                                    if (currentState == '')
                                    {

                     

                                        if (listsViewStack.selectedChild.id == allBills.id)
                                        {

                     

                                            getBills(); //it refreshes the dataGrid

                     


                                        }
                                        else
                                        {

                     


                                            getPayedBills(); //it refreshes the other dataGrid

                     

                     

                     

                                        }

                     

                                    }

                     


                                }

                     

                     

                    What do you think about this solution???

                     

                     

                    Thank you all!!!