6 Replies Latest reply on Jun 6, 2008 6:13 PM by memecpi

    AdvancedDataGrid Sorting

    ANSCORP
      I'm having a problem getting an AdvancedDataGrid to sort data in the proper order. I'm using a GroupingCollection as the dataprovider and I have two fields that are being grouped and sorted correctly. However, the children of the second grouping (the detail records) are not being sorted correctly. I've attempted changing the order in which the data is delivered by the SQL call, I've attempted applying a sort function to both the ArrayCollection and GroupingCollection, but nothing seems to work. If I make the detail records their own group (groupingField), the sort sequence is correct, but the Grid does not look very good that way. Has anyone run into this problem? I thought that identifying the detail field in the GroupingCollection "childrenField" parameter would correct the problem, but it throws an RTE (type coercion error). Any advice would be appreciated.

      Thank You,
      M. McConnell
        • 1. Re: AdvancedDataGrid Sorting
          Sreenivas R Adobe Employee
          To get sorting to work properly you need to apply sorting after supplying GroupingCollection as dataProvider to ADG and refreshing it.

          adg.dataProvider = gc;
          gc.refresh();
          adg.dataProvider.sort = new Sort();
          ...set up fields....

          Have you followed these steps? If you have and still it is not working it would be of great help if you can post some sample code which shows the problem.
          • 2. Re: AdvancedDataGrid Sorting
            ANSCORP Level 1
            Yes....I had already tried that method. It did not work for me. I can't reveal too much of the code, but here is the Actionscript function that receives the database query results and proceeds to populate the GroupingCollection and ADG:

            private function getMarginReport_result(event:ResultEvent):void{
            marginReportData = event.result as ArrayCollection;
            this.invDate = new Date(this.marginReportData[0].invoicedate);
            this.weDate = new Date(this.marginReportData[0].weekenddate);
            this.pwDate = new Date(this.marginReportData[0].pwinvoicedate);
            this.marginReportHeader = "Margin Report for Billing Date " + formatDate.format(this.invDate) + " for Activity Week Ending " + formatDate.format(this.weDate);
            gc.source = marginReportData;
            adg.dataProvider = gc;
            gc.refresh();
            adg.dataProvider.sort = new Sort();
            adg.dataProvider.sort.fields = [new SortField("mr1empclass", true, false), new SortField("mr1branchid", true, false)];
            adg.dataProvider.refresh();
            adg.validateNow();
            adg.expandAll();
            }

            "gc" is defined in the MXML. "mr1branchid" is the detail data that appears when you expand all the parent nodes. The problem is, when I get the "mr1empclass" field to sort correctly, "mr1branchid" gets out of order and when I get "mr1branchid" to sort correctly, "mr1empclass" gets out of order. It's the craziest thing I've ever seen and I've been working on this problem for a week now. Any insight would be appreciated.

            Thank You,
            M. McConnell
            • 3. Re: AdvancedDataGrid Sorting
              memecpi
              It seems that sorting the data causes the summary rows to be misplaced. For example, a summary row that was once placed first now appears at the bottom of the grouping.

              Do you know how I can avoid this or place the summary row at the top again before it's displayed?

              Thanks,
              C. Irwin
              • 4. Re: AdvancedDataGrid Sorting
                Sreenivas R Adobe Employee
                quote:

                Originally posted by: ANSCORP
                The problem is, when I get the "mr1empclass" field to sort correctly, "mr1branchid" gets out of order and when I get "mr1branchid" to sort correctly, "mr1empclass" gets out of order.
                Thank You,
                M. McConnell


                Can you at least show a sample output which shows the incorrect sorting?
                • 5. Re: AdvancedDataGrid Sorting
                  memecpi Level 1
                  Thanks for the quick reply!

                  I will put together a quick example and post it today.

                  thanks
                  • 6. Re: AdvancedDataGrid Sorting
                    memecpi Level 1
                    OK, my first problem is that when I group the data in the Adv. Data Grid, it reorders the records in the group. That is why I had to create a sort in the first place. My second problem I mentioned in my original post seems to be because I am using summary rows with custom AdvancedDataGridItemRenderers and the sort doesn't know how to handle the custom summaries. I believe this is because I am sorting on a date field that has no value in the custom renderer. I can post code for this second problem later. It's even more code.

                    First here is the code to show the grouping reorders my records.

                    Notice how in the first and third group the records have been reordered, but not in the third.

                    Sorry for the huge chunk of code.

                    And thanks again for your help!

                    -chris