2 Replies Latest reply on May 5, 2011 7:02 AM by Milo[HUN]

    AdvancedDatagrid sorting except one specified row




      I'm using AdvancedDatagrid, and I'd like to make a summary row into it. That's the easiest part, but problem is on placing this summary row to the top of the grid (that's gonna be the first row, and all other datas are below), and sorting just ruin the order. I'm havin an own sortCompareFunction that makes the sorting, try to explain it with a simple sample:

      Grid datas are: ID, Name Price like

      ID     Name     Price

      1     xxx          15

      2     yyy          25

      0                    40


      The data with q ID is the summary row.

      The sortCompareFunction is:

      function mySortFunc(itemA:object, itemB:Object):int


           if(itemA['ID'] == 0 || itemB['ID'] == 0)

                return 0;          // as for 0 means each comparable items are equal, therefore no changes be made


                // my own compare algorythm ...



      If summary row is on the bottom of the grid, this sort just works fine, summary row stays at the end of the grid. But if it's placed to the top, after sorting it gets to the middle of the grid between the datas. That is annoying, because my goal is not to sort that row, somehow tell the mechanism not to take that row into consideration as if that's not part of the dataProvider.

      I was trying the listen to dataProvider's CollectionEvent.COLLECTION_CHANGE event, that is dispatched after the provider is changed. And after that I put the summary row to the first place. That worked fine except for the further sorting is stopped.


      Any help would be great.


        • 1. Re: AdvancedDatagrid sorting except one specified row



          I'd suggest changing it to


          function mySortFunc(itemA:object, itemB:Object):int


            if (itemA['ID'] == 0)

              return -1; //summary row goes before everything

            if (itemB['ID'] == 0)

              return 1; //everything goes after summary row




          // my own compare algorythm ...




          In general, best practice is to never return 0 unless itemA==itemB, and that should not happen either.



          • 2. Re: AdvancedDatagrid sorting except one specified row
            Milo[HUN] Level 1

            Unfortunately this won't work properly, I've already tried. Also made a variable flag for the sorting order to make difference between descending and ascending sort and used your idea depending on the flag's state. For the first sorting it worked fine, but changing the sorting order it went wrong once, and after that each sorting went well afterwards. So it was nearly a good idea, but somehow it's just not work like it's expected.