10 Replies Latest reply on Nov 30, 2008 11:46 PM by gallaharsha

    DataGrid Refreshing Problem

      Hi All,

      First let me explain my problem clearly.I am facing the problem with refreshing datagrid for add,update,delete operations.
      For adding task(todo app) i am using another mxml component(PopUpwindow).when i do add,delete or update, changes are happening
      in database pakka and fine.There is no error in that.Only problem is when i add or delete or update a task, datagrid has to
      get refresh with the updated or new data.Then only from ui user will know that he added a task or deleted a task etc right.
      sometimes it's refreshing fine and sometimes not.If it doesn't refresh at all times i can think of my logic.But if it's
      happening sometimes and sometimes not.

      after add or delete or update am using below 5 lines of code to refresh datagrid.

      getList.send(); //sending request again to load new data using httpservice.
      datagrid.dataProvider = resultList; //resultList is bindabale ArrayCollection variable.
      resultList.refresh(); //this line not all giving any changes.i think it's not working

      Thnaks & Regards,
        • 1. DataGrid Refreshing Problem
          gallaharsha Level 1
          I do not know the exact reason as to why your logic does not work but i can share something which is working fine with me.
          Whenever you trigger an event of add or delete or update or whatever which alters the list in the backend you send http request to get new data.
          To put it simple, suppose you add a task, you send it to the backend through http service and on receiving a result trigger update of the datagrid. Iam posting along here sample code. I have a form which updates a refresh rate so when i updata , a http service is sent and the result is handled by handlePlain()

          hope this solves your issue..
          • 2. Re: DataGrid Refreshing Problem
            premadas Level 1

            Hi GallaHarsha,
            here i'm using DataGrid with three buttons.If click on addtask button one popupwindow will open with form fileds after entering the details in the form the user click on the button that will store in Database using HTTPService,JSP.After sending the data to database then again i'm sending the request to get the data from database and diplay in DataGrid but it is not happening why?.

            Thanks & Regards,
            • 3. Re: DataGrid Refreshing Problem
              chris.huston.t10 Level 3
              You need to have your getList.send() call and your dataProvider assignment in two different functions. So, call your HTTPService in one function and then listen for the result in a different function by setting the result event. This is because HTTPService is an asynchronous event.

              • 4. Re: DataGrid Refreshing Problem
                gallaharsha Level 1
                what i meant was the same as Masamune...
                The code above is similar to what Masamune suggests and thats the right approach..
                So whenever a popup opens either for adding or deleting etc.handle the result of http service where you invoke getting datagrid table again..
                Hope that solves the problem
                • 5. Re: DataGrid Refreshing Problem
                  premadas Level 1
                  hi harsha,
                  I'm also using the getHttpServiceObj.send() method.
                  After sending the data to database i'm using the above method only for getting the data but i didn't get the data from database sometimes.

                  For Add i'm using the following code......
                  For Delete also same

                  Anything i need to use except the above lines of code.

                  Thanks & Regards,

                  • 6. Re: DataGrid Refreshing Problem
                    gallaharsha Level 1
                    seems to be fine with your code but are you handling the result event of the httpservice you are sending. Let me make it clear..

                    Initially at the start of application you have the datagrid populated by httpservice through some mehtod invocation.
                    Now you want to add a task, a popup comes which invokes a http service to add the task in the backend and in that HttpService handle the result by setting result="someFuctionwhichgets the dataprovider associated with the data from the backend" , this function invokes a httpservice again to get the fresh table..

                    Hope you got it...
                    • 7. Re: DataGrid Refreshing Problem
                      premadas Level 1
                      Hey Harsha,
                      Same thing i have done what u said in the earlier scrap.While Adding the task it's working and refreshing the arraycollection also but now the problem is Deleting the task.While Deleting the task,the particular task is deleted from the database but data is not refreshing what is the problem behind that.

                      Thanks & Regards,
                      • 8. Re: DataGrid Refreshing Problem
                        gallaharsha Level 1
                        you can do the same thing with delete also,
                        whenever u delete a task you delete in the database by making a httpservice call right,,
                        in the result of that u give the same function which u have used to refresh the table after adding ..
                        Simply put...
                        whenever you think there is change in the database table invoke the function which makes http call to update the table in the ui..
                        hope it is clear....
                        • 9. Re: DataGrid Refreshing Problem
                          premadas Level 1
                          Hey harsha,
                          the following code i'm using for deleting a task.

                          <mx:HTTPService id="getTodo" url=" http://dev.edinc.in:8080/poc/ToDo/GetToDo.jsp" result="resultHandler(event)"/>

                          private function delTask():void

                          deltaskname.text = "";
                          deltaskdate.selectedDate = new Date();
                          deltaskcategory.selectedIndex = -1;
                          deltaskpriority.selectedIndex = -1;
                          deltaskstatus.selectedIndex = -1;

                          Anything i need to apply here.

                          Thanks & Regards,
                          • 10. DataGrid Refreshing Problem
                            gallaharsha Level 1
                            you are using getTodo.send() service to get the todo list in the datagrid, hope i understood it right,
                            Then donot give the command getTodo.send() immediately after delTodo.send(delData) rather, u have a http service with id="delTodo".
                            In that http service put result="successHandler(event)"

                            private fuction successHandler(event:ResultEvent):void{