Hi all,

I have an Advanced datagrid(ADG) which displays nested data. The problem
comes when I use HierarchicalData as the dataprovider for my ADG instead of
a simple ArrayCollection; in this case the column sort functionality ceases
to work and this happens for those columns which have a custom sort compare
function specified for them. Is there any known issue with ADG which can
cause this sort of behaviour? Here is the markup I'm using:

<mx:Script>
        <![CDATA[
                import 
mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;

                import mx.utils.ObjectUtil;
                import mx.collections.ArrayCollection;
                
                [Bindable]              
                private var dp:ArrayCollection;
                
                private function onComplete(event:Event):void
                {
                        var arr:Array = [
                                { 'data':
                                        { 'name': 'tataku', 'date': new 
Date(2009, 12, 4), 'amt': 123.45 },
                                  'outer': 'hithere'
                                },
                                { 'data':
                                        { 'name': 'Taka', 'date': new 
Date(2009, 12, 1), 'amt': 555.45 },
                                  'outer': 'ytheere'
                                },
                                { 'data':
                                        { 'name': 'chamaku', 'date': new 
Date(2009, 12, 2), 'amt': 889.334 },
                                  'outer': 'athere'
                                }
                        ];
                        dp = new ArrayCollection(arr);
                }
                
                private function amtLabelFunc(itemA:Object,
column:AdvancedDataGridColumn):String
                {
                        return itemA.data.amt;
                }
                
                private function amtCompareFunc(itemA:Object, itemB:Object):int
                {
                        return ObjectUtil.compare(itemA.data.amt, 
itemB.data.amt);
                }
                
                private function dateLabelFunc(itemA:Object,
column:AdvancedDataGridColumn):String
                {
                        return itemA.data.date;
                }
                
                private function dateCompareFunc(itemA:Object, itemB:Object):int
                {
                        return ObjectUtil.dateCompare(itemA.data.date as Date, 
itemB.data.date as
Date);
                }
                
                private function nameLabelFunc(itemA:Object,
column:AdvancedDataGridColumn):String
                {
                        return itemA.data.name;
                }
        ]]>
</mx:Script>

<mx:AdvancedDataGrid width="100%" variableRowHeight="true"
sortExpertMode="true" id="myAdg"
        defaultLeafIcon="{null}" folderClosedIcon="{null}" 
folderOpenIcon="{null}"
height="97%"
        creationComplete="onComplete(event)" sortableColumns="true">
        <!-- replacing the below HierarchicalData with ArrayCollection restores 
the
default behaviour! -->
        <mx:dataProvider>
                <mx:HierarchicalData source="{dp}" />
        </mx:dataProvider>
        <mx:columns>
                <mx:AdvancedDataGridColumn headerText="Amount"
labelFunction="amtLabelFunc"
                        sortable="true" sortCompareFunction="amtCompareFunc" />
                <mx:AdvancedDataGridColumn headerText="Date" 
labelFunction="dateLabelFunc"
                        sortCompareFunction="dateCompareFunc" />
                <mx:AdvancedDataGridColumn headerText="Name" 
labelFunction="nameLabelFunc"
/>
                <mx:AdvancedDataGridColumn headerText="Name" dataField="outer" 
/>
        </mx:columns>
</mx:AdvancedDataGrid>

Any ideas/suggestions greatly appreciated.

TIA,
sasuke
-- 
View this message in context: 
http://old.nabble.com/Advanced-Datagrids-and-sortCompareFunctions-for-columns-with-custom-sort-compare-function-tp27205919p27205919.html
Sent from the FlexCoders mailing list archive at Nabble.com.

Reply via email to