4 Replies Latest reply on Mar 5, 2010 9:10 AM by tntomek

    Disable sort when values in grid change (on propertyChange)

    tntomek Level 1

      I don't want my grid reordering itself on every propertyChanged event that would cause the sort order to change, can I prevent this somehow?


      I understand this is default behavior but it's not an option for our customer, and it is really annoying when the 1000 row grid is re-ordered every time user changes any values, not to mention slow.


      I tried returning 0 from sortComparer with no luck, grid still seems to reorder itself according to original data provider and not the sorted view when sort() was set.


      Specifically using AdvancedDataGrid and I'm starting to run out of ideas. Do I reset the dataprovider every time I decide to change my sort? I'm already intercepting headerRelease and setting sort explicitly as well as calling sort from controls outside the grid. How would I get the currently sorted list from my ArrayCollection, does the baseclass CollectionView have a current sorted view? Is there really no way to take a snapshot or current view and set it to current? Is there a way to tell sort() to physically move the rows instead of maintaining a view?


      What I found online:
      Not an option since grid is sortable, I just want to suppress the updates AFTER initial sort

        • 1. Re: Disable sort when values in grid change (on propertyChange)

          I have the same issue when I update a row that has a checkbox editor.  This is very frustrating when you have a lot of rows in the datagrid since the row you just changed disappears from view. It also makes it seem that the row you just unchecked did not change because, since the rows repositioned, the checkbox under the mouse pointer is still checked.

          Did you find a solution?

          • 2. Re: Disable sort when values in grid change (on propertyChange)
            tntomek Level 1

            My fix is less than ideal. As far as I can tell, you have 2 options (reimplement ListCollectionView or monkey patch it). The place where all the magic happens is a private method so there is no clean way to extend class.


            Make your own ArrayCollection and ListCollectionView and modify them. You can just copy paste them and use as your own. This is a lot of work if you want to replace them correctly so might be easier to just monkey patch them (copy paste classes exactly into your own project and make folders like mx.collections.aaa) google flex monkey patch for more info.


            Here is what I did.


            I introduced a new variable to ListCollectionView.as


            * Prevents collection from reordering itself when values change, list is only re-ordered on refresh()
            public var enablePostSortReorder:Boolean = true; //this is what framwork does by default, set to false to do what you want but better do this in yoru ArrayColleciton class (see below)



            In private function handlePropertyChangeEvents(events:Array):void




            if (sort || filterFunction != null)




            if (enablePostSortReorder && (sort || filterFunction != null))



            You will probably also want to extend ArrayCollection. i.e.


            public class CustomArrayCollection extends ArrayCollection


            public function CustomArrayCollection(source:Array = null)
                    enablePostSortReorder = false;
                    this.source = source;



            Hope this helps you, I've been using this solution for a while now in a very big ADG.

            • 3. Re: Disable sort when values in grid change (on propertyChange)
              JimBrychka Level 1

              Thanks for supplying your code changes.  Based on these changes, it looks like you do not allow sorting by clicking on the column header.  Is this assumption accurate?


              Just curious, how many rows and columns do you have in this big ADG?  The reason I ask is that one of my ADG has 20 columns and has up to 30,000 rows.  It's painfully slow when you need to sort the data and we are trying to figure how to redesign it.

              • 4. Re: Disable sort when values in grid change (on propertyChange)
                tntomek Level 1



                Quite the contrary, this change has no additional side effects with regards to regular sorting. Notice that this method is ONLY fired when propertyChange happens. If you trace it back up the stack you will see its not connected to the refresh() method called when you change sort (be it programatically or via clicking header and having Flex grid do it for you).


                We try to keep it under 5000 rows x 50 columns but that is because the backend query is complex and starts to seriously impact database availability.


                Are you using objects for your dataProvider? Sorting even 25k rows shouldn't be a problem for ActionScript. You may want to investigate sorting a plain Array vs ArrayCollection ArrayCollection (IListCollectionView/ICollectionView) dont really sort your data like you think, they keep pointers to records but dont touch internal array.


                My other question for 30k rows is why  it's not very realistic for users to expect this from a web app. I'm sure this is something you will consider in your re-design, we constantly ask ourselves 'do users really need all that data? can they consume it'