4 Replies Latest reply on Mar 31, 2010 9:51 AM by =VA=FyreHeart

    AdvancedDataGrid with multiple custom sort functions

    =VA=FyreHeart Level 2

      I have an AdvancedDataGrid with several levels of nested data in which each level needs to have a custom sort.

       

      Ex:

      A

           Z

                C

                D

                A

           Y

                C

                D

                A

           X

                C

                D

                A

      B

           Z

                C

                D

                A

      etc...

       

      Is this possible without a massive sort function that takes every possible combination into account? Better yet, I'm already sorting it in SQL - can I disable the automatic sort and just have it spit out the data in the order XML passes it to ActionScript?

       

      Thanks

        • 1. Re: AdvancedDataGrid with multiple custom sort functions
          archemedia Level 4

          Yes, you can set the sortableColumns property to false

           

          Dany

          • 2. Re: AdvancedDataGrid with multiple custom sort functions
            =VA=FyreHeart Level 2

            Thanks for the tip, but unfortunately that's not what I'm looking for. I'm not trying to remove the end users' ability to sort, I'm trying to disable the automatic alphabetic sort that the ArrayCollection/AdvancedDataGrid does when it first renders the table. I know it can be overridden by using the "compareFunction" callback, but the compareFunction only iterates through the rows once, and I effectively need something that will iterate through 3 times - one for each nesting level.

             

            The cookbook suggests concatenating the fields and then applying the sorting logic, but that works best if you're applying the same sort to every level of nesting. In my case, it means a massive function along the lines of:

             

            switch(concat_fields1) {

                 case 'AZC':

                      switch(concat_fields2) {

                           case 'AZD':

             

                                return 1;

                                break;

                           default:

                                return -1;

                                break;

                      }

                      break;

                 case 'AZD':

                      etc.

             

            So far, that's the only solution I've found.

            • 3. Re: AdvancedDataGrid with multiple custom sort functions
              archemedia Level 4

              Can't you use 'nested' arrays as a dataProvider?

               

              Like:

               

              myArray = [{id: 1, children: [{id: 2, children: null}, {id: 3, children: null}]}, {id: 4, children: null}];

              You can bind an array like this to the advancedDataGrid.

               

              you can then call sortfunction of each array, or write a function which does this recursively.

               

              Or am I still misunderstanding it?

               

              Dany

              • 4. Re: AdvancedDataGrid with multiple custom sort functions
                =VA=FyreHeart Level 2

                I finally got around to trying this, and passing a formatted array to the ADG like you suggested doesn't really help. I just get a flat ADG with a bunch of [object Object] entries. Defining a GroupingCollection will get me the data, but it's still flat, and it still has the default sort.