8 Replies Latest reply on Sep 6, 2008 8:03 AM by Newsgroup_User

    How you update and AdvancedDataGrid

    denisputnam
      Can someone tell me how to easily update the contents of an AdvancedDataGrid that uses a grouping on an ArrayCollection? The original contents to the ArrayCollection is populated by an HTTP service.
        • 1. Re: How you update and AdvancedDataGrid
          Level 7
          refresh?
          "denisputnam" <webforumsuser@macromedia.com> wrote in message
          news:g9pl3v$76f$1@forums.macromedia.com...
          > Can someone tell me how to easily update the contents of an
          > AdvancedDataGrid that uses a grouping on an ArrayCollection? The original
          > contents to the ArrayCollection is populated by an HTTP service.


          • 2. Re: How you update and AdvancedDataGrid
            SujitG Level 2
            Hi,

            As Amy mentioned try ArrayCollection.refresh() method. Please find more details at the URL below.

            http://livedocs.adobe.com/flex/3/langref/mx/collections/ListCollectionView.html#refresh()
            • 3. Re: How you update and AdvancedDataGrid
              denisputnam Level 1
              Hi,

              Thank you for the refresh() suggestion, but more specifically, how do I change the contents of the array collection before I call refresh and will the AdvancedDataGrid reflect the change on the screen if I change the contents in the array collection? The array collection has been "Group'ed". If I refresh the array collection, do I also have to refresh the Group and do I also have to refresh the AdvancedDataGrid, or is all this automatic?
              • 4. Re: How you update and AdvancedDataGrid
                Level 7

                "denisputnam" <webforumsuser@macromedia.com> wrote in message
                news:g9rhma$b02$1@forums.macromedia.com...
                > Hi,
                >
                > Thank you for the refresh() suggestion, but more specifically, how do I
                > change
                > the contents of the array collection before I call refresh and will the
                > AdvancedDataGrid reflect the change on the screen if I change the contents
                > in
                > the array collection? The array collection has been "Group'ed". If I
                > refresh
                > the array collection, do I also have to refresh the Group and do I also
                > have to
                > refresh the AdvancedDataGrid, or is all this automatic?

                I think you just need to refresh the GroupingCollection.

                HTH;

                Amy


                • 5. Re: How you update and AdvancedDataGrid
                  denisputnam Level 1
                  Hi Amy,

                  So how do I change the value within a specific row and column (cell) of the Array collection? The grouping.refresh() will cause the original contents to be displayed right? I want the new contents to be displayed. Does the refresh() cause the GroupCollection to collapse or will it stay expanded?

                  In my application, I have one of the GroupCollection columns displayed as a CheckBox. When the AdvancedDataGrid initially displays, the check boxes are either checked or unchecked depending on the values received from the HTTP Service request. I haven't been able to get the click change to be be reflected in the original ArrayCollection so that when the user collapses and expands on the Grouping column the checkbox goes back to it's original state. I want it to reflect what the user did. In other words, when the user checks the box, I want the application to update the ArrayCollection in memory so that when the GroupCollection is refreshed it shows the new state.

                  If you go to http://freedom.dynalias.org:8080/moveit/MoveIt.html you can see the application. Click on the check boxes and then click on the ClientName field twice. You will note that the checkboxes go back to their original state. I want them to remember what the user did.

                  Thanks for any help that you can give me.
                  • 6. Re: How you update and AdvancedDataGrid
                    Level 7

                    "denisputnam" <webforumsuser@macromedia.com> wrote in message
                    news:g9rnhl$h9j$1@forums.macromedia.com...
                    > Hi Amy,
                    >
                    > So how do I change the value within a specific row and column (cell) of
                    > the
                    > Array collection?

                    That depends on what is in it.

                    > The grouping.refresh() will cause the original contents to
                    > be displayed right?

                    If the ArrayCollection hasn't dispatched any events to say it has changed,
                    that is possible.

                    >I want the new contents to be displayed. Does the
                    > refresh() cause the GroupCollection to collapse or will it stay expanded?

                    Try it and see. A lot of your questions could be answered faster by trying
                    it than by typing more questions here.


                    • 7. Re: How you update and AdvancedDataGrid
                      denisputnam Level 1
                      Hi Amy,

                      I apologize if I have given any offense. I did try everything that you said, but to no avail. I have found the solution however.

                      The solution to the problem is the

                      this.dispatchEvent( new mx.events.FlexEvent( mx.events.FlexEvent.DATA_CHANGE, true, false ) );

                      line of code in the MyCheckBox.update() method and the

                      private function basicTranferInfoGridChangeHandler(evt:Event):void

                      handler in the main code section.

                      Firing the FlexEvent.DATA_CHANGE causes the basicTransferInfoGridChangeHandler() to be invoked. The code is then able to examine current state of the data in the myTransferInfoAC ArrayCollection and then modify it based on the row and column that was selected by the user. I would have liked to change the the data in myTransferInfoAC ArrayCollection inside the MyCheckBox.update() method, but I have not been able to figure that out yet. Perhaps you have a suggestion.

                      I found it interesting that the

                      var myArr:Array = this.myTransferInfoAC.toArray();

                      line of code in the handler actually creates a reference to the original array collection and not a copy. This makes it uneccessary to "refresh()" the GroupCollection because everything seemed to be accessed through the myArr reference. I am assuming that if you want a real copy of the array collection that you would have to use the "new" operator.

                      The "refresh()" does cause the AdvancedDataGrid item to collapse, so I am happy the the myArr reference does the trick.

                      I appreciate your responding to my question. I have been trying to figure this out for about a week. Any other insight or best practices advice that you might have would be greatly appreciated.

                      -Denis
                      • 8. Re: How you update and AdvancedDataGrid
                        Level 7

                        "denisputnam" <webforumsuser@macromedia.com> wrote in message
                        news:g9s4t3$297$1@forums.macromedia.com...
                        > Hi Amy,
                        >
                        > I apologize if I have given any offense. I did try everything that you
                        > said,
                        > but to no avail. I have found the solution however.

                        I'm not offended, but remember that Flex is vast and the people on here only
                        know what they know. I don't think it's possible to encounter every
                        situation Flex has to offer, even if you develop in Flex for 10 years, which
                        notbody has yet.

                        So when you say "what happens when I ___" and it is something that will take
                        10 seconds for you to try, but might take me an hour to build an example
                        file and try it, guess what...I'm not going to try it. If I happen to know
                        the answer, great, but if you take the 10 seconds and say "I tried ___ and
                        here's what happened," I might have an alternative approach I can suggest
                        based on what happened. So it's in your best interest to go ahead and take
                        that extra step, because you can bet it's going to be very rare that anyone
                        here has time to take it for you.

                        > The solution to the problem is the
                        >
                        > this.dispatchEvent( new mx.events.FlexEvent(
                        > mx.events.FlexEvent.DATA_CHANGE,
                        > true, false ) );
                        >
                        > line of code in the MyCheckBox.update() method and the
                        >
                        > private function basicTranferInfoGridChangeHandler(evt:Event):void
                        >
                        > handler in the main code section.
                        >
                        > Firing the FlexEvent.DATA_CHANGE causes the
                        > basicTransferInfoGridChangeHandler() to be invoked. The code is then able
                        > to
                        > examine current state of the data in the myTransferInfoAC ArrayCollection
                        > and
                        > then modify it based on the row and column that was selected by the user.
                        > I
                        > would have liked to change the the data in myTransferInfoAC
                        > ArrayCollection
                        > inside the MyCheckBox.update() method, but I have not been able to figure
                        > that
                        > out yet. Perhaps you have a suggestion.
                        >
                        > I found it interesting that the
                        >
                        > var myArr:Array = this.myTransferInfoAC.toArray();
                        >
                        > line of code in the handler actually creates a reference to the original
                        > array
                        > collection and not a copy.

                        That should actually make an array, not an ArrayCollection.

                        >This makes it uneccessary to "refresh()" the
                        > GroupCollection because everything seemed to be accessed through the myArr
                        > reference. I am assuming that if you want a real copy of the array
                        > collection
                        > that you would have to use the "new" operator.

                        I doubt that would actually work, because it would still have the same
                        source. You'd have to copy the array into a new array, then use that as the
                        source. I believe that refreshing either collection would work, since they
                        share the same source, ultimately. I just pointed you at the most obvious
                        one.

                        > The "refresh()" does cause the AdvancedDataGrid item to collapse, so I am
                        > happy the the myArr reference does the trick.

                        See :-) You found that out all on your own....

                        > I appreciate your responding to my question. I have been trying to figure
                        > this out for about a week. Any other insight or best practices advice
                        > that you
                        > might have would be greatly appreciated.

                        The reason you had to dispatch a dataChange was because you didn't include
                        the super of set data. When you only changed the value of your internal
                        value, rather than calling the data setter, the event wasn't dispatched. Of
                        course, you'd need the super in it to get it to handle it for you. By
                        dispatching the dataChange, you forced the collection to go back and use the
                        getter. There's no way anyone could have known what was wrong without
                        seeing your itemRenderer code.

                        Here are some links about using check boxes as itemRenderers. At the least
                        you should probably look at implementing IDropInListItemRenderer, so you're
                        not hardcoding the column.

                        http://blogs.adobe.com/aharui/2008/02/checkbox_selection_in_datagrid.html
                        http://www.returnundefined.com/2007/11/efficient-reusable-and-centered-checkbox-renderers- for-datagrids

                        HTH;

                        Amy