2 Replies Latest reply on Jan 30, 2009 10:17 PM by John Hall

    Advanced Data Grid Sorting / Grouping Collection

    AnakinJay Level 1
      Ok, basically here's the issue..

      I have an advanced data grid with a tree view. It goes two levels deep
      so:
      Report Type
      |-------------------- Company
      |--------------------------------------- Report 1
      |--------------------------------------- Report 2
      |--------------------------------------- Report 3
      |-------------------- Company 2
      |--------------------------------------- Report 1
      |--------------------------------------- Report 2
      |--------------------------------------- Report 3

      Report Type 2
      |-------------------- Company
      |--------------------------------------- Report 1
      |--------------------------------------- Report 2
      |--------------------------------------- Report 3
      |-------------------- Company 2
      |--------------------------------------- Report 1
      |--------------------------------------- Report 2
      |--------------------------------------- Report 3
      etc..

      Report and Company are Nodes (folders) and are being sorted alphabetically by default.
      The individual reports (Report 1,2,3, etc..) are not being sorted in any way that I can figure out. I need to sort them by date, but no matter what I've tried I can't get it to work.

      I tried a SortCompareFunction on the advancedDataGridColumn that displays each report, and it works *IF* I click the header... but if I dispatch the header_release event via AS3, nothing happens.

      I even set up a test:
      dg.addEventListener(AdvancedDataGridEvent.HEADER_RELEASE,heard);

      dg.dispatchEvent(

      new AdvancedDataGridEvent
      (
      AdvancedDataGridEvent.HEADER_RELEASE,
      false,
      true,
      0, // The zero-based index of the column to sort in the DataGrid object's columns array.
      null,
      0,
      null,
      null,
      0
      )

      );

      function heard(e:Event) {

      trace("I HEAR IT!");
      trace(e.type);

      }


      I set that up on a button so I can dispatch the event with a click. Every time I click the button, the header release event listener goes off, but the actual advanceddatagrid remains unchanged until I actually click on it's header..

      Any help would be *GREATLY* appreciated... I've been stuck on this problem for two days now :(
        • 1. Re: Advanced Data Grid Sorting / Grouping Collection
          Level 7

          "AnakinJay" <webforumsuser@macromedia.com> wrote in message
          news:glvh5b$4v1$1@forums.macromedia.com...
          > Ok, basically here's the issue..
          >
          > I have an advanced data grid with a tree view. It goes two levels deep
          > so:
          > Report Type
          > |-------------------- Company
          > |--------------------------------------- Report 1
          > |--------------------------------------- Report 2
          > |--------------------------------------- Report 3
          > |-------------------- Company 2
          > |--------------------------------------- Report 1
          > |--------------------------------------- Report 2
          > |--------------------------------------- Report 3
          >
          > Report Type 2
          > |-------------------- Company
          > |--------------------------------------- Report 1
          > |--------------------------------------- Report 2
          > |--------------------------------------- Report 3
          > |-------------------- Company 2
          > |--------------------------------------- Report 1
          > |--------------------------------------- Report 2
          > |--------------------------------------- Report 3
          > etc..
          >
          > Report and Company are Nodes (folders) and are being sorted alphabetically
          > by
          > default.
          > The individual reports (Report 1,2,3, etc..) are not being sorted in any
          > way
          > that I can figure out. I need to sort them by date, but no matter what
          > I've
          > tried I can't get it to work.
          >
          > I tried a SortCompareFunction on the advancedDataGridColumn that displays
          > each
          > report, and it works *IF* I click the header... but if I dispatch the
          > header_release event via AS3, nothing happens.
          >
          > I even set up a test:
          > dg.addEventListener(AdvancedDataGridEvent.HEADER_RELEASE,heard);
          >
          > dg.dispatchEvent(
          >
          > new AdvancedDataGridEvent
          > (
          > AdvancedDataGridEvent.HEADER_RELEASE,
          > false,
          > true,
          > 0, // The zero-based index of the column to sort in the DataGrid object's
          > columns array.
          > null,
          > 0,
          > null,
          > null,
          > 0
          > )
          >
          > );
          >
          > function heard(e:Event) {
          >
          > trace("I HEAR IT!");
          > trace(e.type);
          >
          > }
          >
          >
          > I set that up on a button so I can dispatch the event with a click. Every
          > time I click the button, the header release event listener goes off, but
          > the
          > actual advanceddatagrid remains unchanged until I actually click on it's
          > header..
          >
          > Any help would be *GREATLY* appreciated... I've been stuck on this problem
          > for
          > two days now :(

          Check the compareFunctions here
          http://flexdiary.blogspot.com/2008/09/groupingcollection-example-featuring.html


          • 2. Re: Advanced Data Grid Sorting / Grouping Collection
            John Hall Level 4
            Been down this road. However, I put in a lot more than 2 days :-) Very frustrating. The bottom line is I do not know the PROPER way to do it but assuming I understand the problem, here's how I approached it that finally worked.

            It looks like your grouping collection is going its job if the first two levels are sorted properly. And if your situation is like mine, I could get the third level to sort if I added an additional group field but then I had a superfluous folder that repeated the leaf node. All I wanted was the terminal leaf so I didn't want to add the additional folder.

            Anyway, what I finally go to work, though I'd love to hear if you find a efficient solution, is the following.

            I created the grouping collection using the first two grouping fields for the first two levels. That gave me my grouping collection which I then fed into my ADG's hosting component.

            There instead of using the groupingCollection itself as a dataprovider, I used it as the source of a HierarchicalCollectionView. In my case, with treeGC being the grouping collection:

            <mx:HierarchicalCollectionView id="treeDP" source="{treeGC}"/>

            Then I used the treeDP as the dataProvider for the ADG. However, I still had the issue you had where the final leaf wasn't sorting properly but since it was now a hierarchicalCollectionView, the grouping was preserved when I sorted the final level with something along the following lines whenever I had to refresh the data: