Rendezvous with technology

Adding FLEXibility to sorting hierarchical data

Posted by: Sameer on: July 18, 2007

With the release of Flex 3 Moxie Beta 2, sorting of hierarchical data has been given a new FLEXibility.

Earlier sorting hierarchical data was not possible. With the introduction of Advanced DataGrid and new collections support, we can have new ways to sort Hierarchical data.

Check out the sample here

1. In the first Grid – Sorting can be done recursively on all the nodes and their children.

2. In the second Grid a node can be selected and only its children can be sorted and sort order can be chosen from the ComboBox.

Source code can be found here

6 Responses to "Adding FLEXibility to sorting hierarchical data"

Hi, Iam using groupCollection as data provider in my advance dataGrid.I have my Summary row placed at Group level which in turn is a summary of computed column. i.e I have a field which is showing financial data with a $ sign(Computed Column) and the same field is my summary field.

Now I want to sort my data based on summary Row.I tried using default sorting but it doesnt work and when I sort group column it sorts only child of all nodes not parent nodes.
How should i go about it.Please help its urgent…

For sorting Group Columns make sure that you make the label property in Grouping same as the column dataField.
For example, if the column’s dataField is “name”.
Create your Grouping as –

var gf:Grouping = new Grouping();
gf.label = "name";
gf.fields = [new GroupingField("name")];

For summaries, you can write a custom sort function to do that.

Hi,
When I run your exmple from this page, it works perfectly fine , but when I copy and paste the mxml file to my flex project and run it from there, the right depthwise sorting doesn’t work at all! I know this is so weired! do you have any idea why? I’m using flex 3.0

Thanks
Golnoosh

This code is compiled with Flex 3 Beta 2 as written in the post. So, things might have changed.
Basically, what’s happening here is the sort on the child collection is overwritten by the sort on the IHierarchicalCollection (dataProvider) which is null (there is no sort on the collection).

Hi again,
I thought maybe you can help me since you worked in this area.
I need to do something similar to this! I have advancedDataGrid with flatData. In my UI, users can add grouping and summaries, and filters to ADG. for sorting I want to be able to sort using all the columns no matter if the column is grouped or not!
let’s say the columns are Country, Province, City and Population. and the user grouped the data based on Country and Province.
so sorting based on country, will sort the group of countries, and soring on Province will sort the group of Provinces and sort on city will do the sort all the cities under Province groups

any help will be greatly appreciated,

Thanks
Golnoosh

In the scenario that you mentioned about Country, Province, City and Population with grouping on Country and Province, I think clicking on the City and Population header will be working fine and sorting the collection based on these fields.
Sorting on the grouped fields: Country and Province might not be working. For sorting to work properly on the grouped fields, you need to set Grouping.label property to the dataField of the column in which you are showing it.
Something like – if you are column’s dataField is Country –
<mx:Grouping label=”Country”>
<mx:GroupingField name=”Country” />
</mx:Grouping>

Leave a Reply