Hi GnanaPrakash,

Thanks a lot for your reply. I implemented the first approach and it
worked absolutely fine for me.But i was not able to implement the
second solution. I want this sortCompareFunction to be called from the
MXML file.Here is my code :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
height="100%" width="100%" layout="absolute" creationComplete="init
();" viewSourceURL="srcview/index.html" xmlns:local="*" >
<mx:Script source="CogIntegrator.as"/>
<mx:Script>
        <![CDATA[

        private function fieldNumericSorter(field:String):Function {
    return function (obj1:Object, obj2:Object):int {
        return ( int(obj1[field]) - int(obj2[field]) );
    }

}
        ]]>
</mx:Script>
<mx:VBox height="100%" id="container">
<mx:Button id="restoreButton" label="Restore" click="restoreHandler
(event);" height="3%"/>
<mx:AdvancedDataGrid height="95%" width="100%" id="pricingADG"
dataProvider ="{xmlData}"  >
<mx:columns>
        <mx:AdvancedDataGridColumn  dataField="c_Application"
headerText="Application" headerRenderer="MenuHeaderRenderer"/>
        <mx:AdvancedDataGridColumn  dataField="c_Department"
headerText="Department" headerRenderer="MenuHeaderRenderer"/>
        <mx:AdvancedDataGridColumn  dataField="n_Count"
headerText="Count" headerRenderer="MenuHeaderRenderer"/>
        <mx:AdvancedDataGridColumn  dataField="d_Date"
headerText="Date" sortCompareFunction="fieldNumericSorter("d_Date");" /
>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:VBox>
</mx:Application>

This gives an error : Element type "mx:AdvancedDataGridColumn" must be
followed by either attribute specifications, ">" or "/>".


Could you please implement it for a sample case and show us how can
this global function can be used?

Thanks a lot for your help.

Regards,
Shishir.

On Mar 2, 3:59 pm, GnanaPrakasam T <[email protected]> wrote:
> Hi Shishir,
> If possible Try to make the datatype of that numeric coloumns to Number,
> [You may cast the datasource with custom defined bean class]
> then normal sorting will sort that column as  numberic sorting
> or
> by following logic you can achieve global sortcompare function for all
> the datagrid coloumns
>
> function fieldNumericSorter(field:String):Function {
>     return function (obj1:Object, obj2:Object):int {
>         return sign( int(obj1[field]) - int(obj2[field]) );
>     }
>
> }
>
> colToBeSorted.sortCompareFunction = fieldNumericSorter("fieldname");
>
> Sourcehttp://stackoverflow.com/questions/284164/flex-datagrid-universal-num...
>
> Gnanz.../http://gnanz-flexworld.blogspot.com
>
> Shishir wrote:
> > Hi,
>
> > I want to write a generic numeric sorting function that takes the
> > numeric column and sorts it.Here is my MXML code as of now :
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > height="100%" width="100%" layout="absolute" creationComplete="init
> > ();" viewSourceURL="srcview/index.html" xmlns:local="*" >
> > <mx:Script source="CogIntegrator.as"/>
> > <mx:Script>
> >    <![CDATA[
> > private function sortNumeric(obj1:Object, obj2:Object):int {
> > var value1:Number = (obj1.n_Count == '' || obj1.n_Count == null) ?
> > null : new Number(obj1.n_Count);
> > var value2:Number = (obj2.n_Count == '' || obj2.n_Count == null) ?
> > null : new Number(obj2.n_Count);
> > if (value1 < value2) {
> > return -1;
> > } else if (value1 > value2) {
> > return 1;
> > } else {
> > return 0;
> > }
> > }
> >    ]]>
> > </mx:Script>
> > <mx:VBox height="100%" width="100%">
> > <mx:Button id="restoreButton" label="Restore" click="restoreHandler
> > (event);" height="3%"/>
> > <mx:AdvancedDataGrid height="95%" width="100%" id="pricingADG"
> > dataProvider ="{xmlData}"  >
> > <mx:columns>
> >         <mx:AdvancedDataGridColumn  dataField="c_Application"
> > headerText="Application" headerRenderer="MenuHeaderRenderer"/>
> >         <mx:AdvancedDataGridColumn  dataField="c_Department"
> > headerText="Department" headerRenderer="MenuHeaderRenderer"/>
> >         <mx:AdvancedDataGridColumn  dataField="n_Count"
> > sortCompareFunction="sortNumeric" headerText="Count"
> > headerRenderer="MenuHeaderRenderer"/>
> >         <mx:AdvancedDataGridColumn  dataField="n_Quantity"
> > headerText="Quantity" />
> > </mx:columns>
> > </mx:AdvancedDataGrid>
> > </mx:VBox>
> > </mx:Application>
>
> > The sortNumeric function works fine but it is not generic.Using the
> > above approach i have to define a different sorting function for
> > Quantity column also(have to use obj1.n_Quantity..).Is there a way to
> > somehow get the context of the column so that a generic sortNumeric
> > function can be used to sort all the numeric columns ,rather than me
> > writing a separate sorting function for all the columns?
>
> > Any guidance would be highly appreciated.
>
> > Thanks,
> > Shishir.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to