AdvancedDatagrid Sort

Hi,
I am trying to do a generic sort function for ADG such as:
public static function sortCompareFunction(obj1:Object, obj2:Object, gc:AdvancedDataGridColumn):int {
         return ObjectUtil.numericCompare(Number(obj1[gc.dataField].toString().replace(',','')), Number(obj2[gc.dataField].toString().replace(',','')));
I got the idea from here:
http://cookbooks.adobe.com/post_Sorting_numeric_values_in_a_Flex_DataGrid-2881.html
ArgumentError: Error #1063: Argument count mismatch on assets.valueObjects::Utils$/sortCompareFunction(). Expected 3, got 2.
I am using SDK 4.5.1, can anyone help with this?
Thanks!

Hi,
     I ask you to extend dataridcolumn and create your custom datagird column. this is what you really need.
DgdColumn2.as
package Dg2
    public class DgdColumn2 extends DataGridColumn
        public function SrtCmpFnNumeric(objItem1:Object, objItem2:Object):int
            return ObjectUtil.numericCompare(objItem1[dataField], objItem2[dataField]);
in your main.as
var dgdClmn:DgdColumn2;
var column:Array = new Array();
for(var i:int = 0; i < 10; i++)
    dgdClmn = new DgdColumn2();
    dgdClmn.sortCompareFunction = dgdClmn.SrtCmpFnNumeric;
    column.push(dgdClmn);
datagrid.columns = column;

Similar Messages

  • Slow performance with custom comparator (AdvancedDataGrid sorting)

    I'm using Flex 3.4.
    I have an advancedDataGrid. Have 2 columns with numbers as data.
    For one column, I do not set any custom comparator function.
    For the other column, I set a custom comparator function which is exactly the same as the default one used by Flex. (The private function SortField.numericCompare).
    For both columns, I set the same data - 3000 Rows with values either 0 or 1.
    When i sort on column1 (the one with custom comparator), the sorting is much slower than on column2 (default Flex comparator).
    I went through the AdvancedDataGrid/SortField source codes but could not see why this could be happening as the comparator functions are the same in both cases.
    Also, I checked out this bug -
    http://bugs.adobe.com/jira/browse/SDK-13118
    But shouldn't this be applicable to both custom and default sorting?
    Can anyone help me out?

    This is the function that i have : (same as the SortField numericCompare function which is the default function which is used if no customCompare is specified.)
            public function numCompare(a:Object, b:Object):int {
                var fa:Number;
                try {
                    fa = _name == null ? Number(a) : Number(a[_name]);
                } catch (error:Error) {
                var fb:Number;
                try {
                    fb = _name == null ? Number(b) : Number(b[_name]);
                } catch (error:Error) {
                return ObjectUtil.numericCompare(fa, fb);
    As per bug, the performance should be slow for lots of items that have same value. But, it should be the same for both the custom compare and the default compare as the custom compare function I'm using is the same as what is used for Flex.

  • AdvancedDatagrid sorting except one specified row

    Hi!
    I'm using AdvancedDatagrid, and I'd like to make a summary row into it. That's the easiest part, but problem is on placing this summary row to the top of the grid (that's gonna be the first row, and all other datas are below), and sorting just ruin the order. I'm havin an own sortCompareFunction that makes the sorting, try to explain it with a simple sample:
    Grid datas are: ID, Name Price like
    ID     Name     Price
    1     xxx          15
    2     yyy          25
    0                    40
    The data with q ID is the summary row.
    The sortCompareFunction is:
    function mySortFunc(itemA:object, itemB:Object):int
         if(itemA['ID'] == 0 || itemB['ID'] == 0)
              return 0;          // as for 0 means each comparable items are equal, therefore no changes be made
         else
              // my own compare algorythm ...
    If summary row is on the bottom of the grid, this sort just works fine, summary row stays at the end of the grid. But if it's placed to the top, after sorting it gets to the middle of the grid between the datas. That is annoying, because my goal is not to sort that row, somehow tell the mechanism not to take that row into consideration as if that's not part of the dataProvider.
    I was trying the listen to dataProvider's CollectionEvent.COLLECTION_CHANGE event, that is dispatched after the provider is changed. And after that I put the summary row to the first place. That worked fine except for the further sorting is stopped.
    Any help would be great.
    Thanks

    Hello.
    I'd suggest changing it to
    function mySortFunc(itemA:object, itemB:Object):int
      if (itemA['ID'] == 0)
        return -1; //summary row goes before everything
      if (itemB['ID'] == 0)
        return 1; //everything goes after summary row
    else
    // my own compare algorythm ...
    In general, best practice is to never return 0 unless itemA==itemB, and that should not happen either.
      Milan

  • AdvancedDatagrid Sorting Issue

    Hi,
       We have an advanceddatagrid with many columns and one of the columns is Serial Number. When we try to sort any of the columns, the order in which the serial numbers appear is incorrect. Can anyone tell how to sort an advanceddatagrid column while maintaining the correct order of serial number column?
    Thanks in advance.

    I hear you.
    I tried this on one of my large apps with about 100 items in an ADG
    and did not see any performance issue. Might it be that some
    intervening code is contributing to the problem? - just a guess.
    Having said that, if I run an ADG with two item renderers - one of
    them fairly complex, I see a slight but acceptable performance
    degradation - even at about 25 items.
    Don't know what else to say at this point.

  • How can i sort a groupingfield in AdvancedDataGrid

    Hello,
    I have a AdvanceddataGrid, in that i have a groupingfield called "month" which contains months data(ex: April 2011).
    When i populate the data in ADG, the months are not populating in a chronological order. how can i achieve this.
    In this below image, i need to get months in chronological order. i used custom sort for children(1,2,3,4,5,6) and its working fine.. but how can i make this custom sort for chronological order.
    i used this below code, but its only working for alphabetical order. i need to get it done in chronological order.
    private function sortData():void {
        var sort:Sort = new Sort();
        var sortField:SortField = new SortField("Count");
        sort.fields = [sortField];        // Set 'Product' as the field to be sorted on
        myADG.dataProvider.sort = sort;   // Add the sort to the dataProvider of the dataGrid
        gc.source.refresh();              // Refresh the GroupCollection
    can anyone help me out in this issue.

    Select the paragraphs to sort.
    menu Format > Table > Convert text to table
    select the table cells then
    Inspector > Table > Edit Rows and columns > Sort …
    menu Format > Table > Convert table to text.
    Don't worry, no offense, I stopped while writing +BUSCH G.W. is an american president+
    Yvan KOENIG (from FRANCE dimanche 18 mai 2008 17:32:35)

  • AdvancedDatagrid but simple sorting?

    Hi,
    I sue the AdvancedDatagrid because of the nice grouping
    function for columns. I would like to enable sorting but don't like
    the new way of sorting multiple columns.
    1. Is there a way to enable sorting by just 1 column like in
    the normal datagrid?
    2. How can i get rid of the small "1" next to the sort icon
    arrow?
    Cheers

    "niksk" <[email protected]> wrote in message
    news:gn0vo0$5qc$[email protected]..
    >I am also using the advancedDataGrid, for sorting issue i
    did the sortable
    >=
    > true for the columns i want to be sortable and sortable
    = false for
    > others. But
    > that small 1 is a issue for me also.....
    I think there's an expert mode or something that you can use
    that controls
    this...

  • AdvancedDataGrid Scroll/Sort-Bug

    Steps to reproduce:
    Scroll the datagrid to middle position.
    Sort by column "id".
    Change sort order from ascending to descending.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
         <mx:Script>
         <![CDATA[
              import mx.collections.ArrayCollection;
              import mx.collections.HierarchicalData;
              public var testData:ArrayCollection = new ArrayCollection([
                   {id:1,children: [{id:11},{id:12},{id:13}]},
                   {id:2,children: [{id:21},{id:22},{id:23}]},
                   {id:3,children: [{id:31},{id:32},{id:33}]},
                   {id:4,children: [{id:41},{id:42},{id:43}]},
                   {id:5,children: [{id:51},{id:52},{id:53}]},
                   {id:6,children: [{id:61},{id:62},{id:63}]},
                   {id:7,children: [{id:71},{id:72},{id:73}]},
                   {id:8,children: [{id:81},{id:82},{id:83}]},
                   {id:9,children: [{id:91},{id:92},{id:93}]},
                   {id:10,children: [{id:101},{id:102},{id:103}]},
                   {id:11,children: [{id:111},{id:112},{id:113}]},
                   {id:12,children: [{id:121},{id:122},{id:123}]}
         ]]>
         </mx:Script>
         <mx:AdvancedDataGrid width="400" height="200">
              <mx:dataProvider>
                   <mx:HierarchicalData source="{testData}" />
              </mx:dataProvider>
         </mx:AdvancedDataGrid>
    </mx:Application>

    Hi,
    Please find the following code
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
         <mx:Script>
         <![CDATA[
              import mx.collections.ArrayCollection;
              import mx.collections.HierarchicalData;
              public var testData:ArrayCollection = new ArrayCollection([
                   {id:1,children: [{id:11},{id:12},{id:13}]},
                   {id:2,children: [{id:21},{id:22},{id:23}]},
                   {id:3,children: [{id:31},{id:32},{id:33}]},
                   {id:4,children: [{id:41},{id:42},{id:43}]},
                   {id:5,children: [{id:51},{id:52},{id:53}]},
                   {id:6,children: [{id:61},{id:62},{id:63}]},
                   {id:7,children: [{id:71},{id:72},{id:73}]},
                   {id:8,children: [{id:81},{id:82},{id:83}]},
                   {id:9,children: [{id:91},{id:92},{id:93}]},
                   {id:10,children: [{id:101},{id:102},{id:103}]},
                   {id:11,children: [{id:111},{id:112},{id:113}]},
                   {id:12,children: [{id:121},{id:122},{id:123}]}
         ]]>
    private function sortNumeric(obj1:Object, obj2:Object):int {
                var value1:Number = (obj1.id == '' || obj1.id == null) ? null : new Number(obj1.id);
                var value2:Number = (obj2.id == '' || obj2.id == null) ? null : new Number(obj2.id);
                if (value1 < value2) {
                   return -1;
                } else if (value1 > value2) {
                  return 1;
                } else {
                  return 0;
         </mx:Script>
         <mx:AdvancedDataGrid width="400" height="200">
              <mx:dataProvider>
                   <mx:HierarchicalData source="{testData}" />
              </mx:dataProvider>
              <mx:columns>
                        <mx:Array>
                            <mx:DataGridColumn dataField="id" headerText="id" sortCompareFunction="sortNumeric"/>
                        </mx:Array>
                    </mx:columns>
                </mx:DataGrid>
         </mx:AdvancedDataGrid>
    </mx:Application>
    Thank you

  • Sort column in advanceddatagrid

    Hi, i have an interesting question - how to sort column id
    datagrid, like i clicked on a header. I use AdvancedDataGrid and
    HierarchialData

    Yes, it works for HierarchicalCollectionView, but works for
    only first level of the tree. Like I sort an XMLListCollection,
    comparefunction handles only full elements of the first level. I
    need also to sort children nodes of the thee (customer wants).
    I have done it for XMLListCollection which is the source of
    HierarchialData but it's too many letters =)) and i need sort it
    and refresh HierarchialData after every change. Advanced datagrid
    makes it automatically by pressing on a header.
    Here is the code:
    quote:
    public static function
    sortXMLListCollection(xml:XMLListCollection,dataField:String):XMLListCollection
    var sorting:Sort=new Sort();
    sorting.fields=[new SortField(dataField)];
    xml.sort=sorting;
    xml.refresh();
    for each(var item:XML in xml)
    XMLUtils.sortXMLNode(item,sorting);
    return xml;
    public static function
    sortXMLNode(node:XML,sorting:Sort):XML
    var tempXML:XMLListCollection=new XMLListCollection(node.*);
    tempXML.sort=sorting;
    tempXML.refresh();
    XMLUtils.clearNode(node);
    XMLUtils.appendXMLListInXML(node,tempXML.copy());
    for each(var item:XML in node.*)
    XMLUtils.sortXMLNode(item,sorting);
    return node;
    public static function
    appendXMLListInXML(xml:XML,xmlList:XMLList):XML
    for each(var appendXML:XML in xmlList)
    xml.appendChild(appendXML)
    return xml;
    public static function clearNode(xml:XML):XML
    for(var i:int=new
    XMLListCollection(xml.*).length-1;i>=0;i--)
    delete xml.*
    return xml;

  • FB3 M3 Beta2- Advanceddatagrid column header multiple sort

    Hello People,
    Before 10-1 when the M3 B2 of FB3 comes out i had normal
    columnheaders with the new beta version there are suddenly multi
    sort functions added to the columnheaders of the advanced datagrid!
    How can i remove those.. i have alot of columns and now is
    the headertext wordwrapping like nuts!
    -Sjoerd

    You can set the property sortExpertMode to "true" in
    AdvancedDataGrid.
    The vertical line in the AdvancedDataGrid Header is not shown
    when sortExpertMode="true".
    Even then, if the headers does not get wordwraped, please
    file a bug here -
    http://bugs.adobe.com/flex
    Thanks,
    Sameer

  • AdvancedDataGrid, SummaryField2 sorting

    Hi,
    Is there a way to sort an AdvancedDataGrid with summary rows by the summary values (using SUM)?  I'm using a GroupingCollection2 as the data provider for the AdvancedDataGrid with an flat ArrayCollection as the source for the GroupingCollection2.  The original ArrayCollection is sorted in correct order but the end result is the AdvancedDataGrid is displaying the groups/summary rows in alphabetical order.
    Thanks,
    Wade.

    Hello.
    I'd suggest changing it to
    function mySortFunc(itemA:object, itemB:Object):int
      if (itemA['ID'] == 0)
        return -1; //summary row goes before everything
      if (itemB['ID'] == 0)
        return 1; //everything goes after summary row
    else
    // my own compare algorythm ...
    In general, best practice is to never return 0 unless itemA==itemB, and that should not happen either.
      Milan

  • AdvancedDataGrid with multiple custom sort functions

    I have an AdvancedDataGrid with several levels of nested data in which each level needs to have a custom sort.
    Ex:
    A
         Z
              C
              D
              A
         Y
              C
              D
              A
         X
              C
              D
              A
    B
         Z
              C
              D
              A
    etc...
    Is this possible without a massive sort function that takes every possible combination into account? Better yet, I'm already sorting it in SQL - can I disable the automatic sort and just have it spit out the data in the order XML passes it to ActionScript?
    Thanks

    Thanks for the tip, but unfortunately that's not what I'm looking for. I'm not trying to remove the end users' ability to sort, I'm trying to disable the automatic alphabetic sort that the ArrayCollection/AdvancedDataGrid does when it first renders the table. I know it can be overridden by using the "compareFunction" callback, but the compareFunction only iterates through the rows once, and I effectively need something that will iterate through 3 times - one for each nesting level.
    The cookbook suggests concatenating the fields and then applying the sorting logic, but that works best if you're applying the same sort to every level of nesting. In my case, it means a massive function along the lines of:
    switch(concat_fields1) {
         case 'AZC':
              switch(concat_fields2) {
                   case 'AZD':
                        return 1;
                        break;
                   default:
                        return -1;
                        break;
              break;
         case 'AZD':
              etc.
    So far, that's the only solution I've found.

  • Sorting in AdvancedDataGrid

    i have a AdvancedDataGrid with GroupFields and columns. The data of a group is not populating in a sorted order under a column. when i click on column header, then its coming to a order. I need to show the sorted data without clicking on columnheader. Any idea??

    http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and -sort-classes/

  • How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?

    Hello,
    I am using a ADG, which populates the returned data(arraycollection) from database. I'm generating a counter on java side for each returned record and showing that counter in ADGcolumn. I just want to sort that particular column.
    When i debug the application, i'm getting the counter count properly but when its showing in ADG, sorting is missing. when i clicks on coloum header, then only its showing in ascending order, i need to show up in ascending order without clicking on column header.
    Can anyone help me in this issue??

    Hi Johnny,
    Thanks for your helpful code, its really working for me.
    but i have an issue, once i apply the sort, i'm getting number '1' and down arrow symbol on ADGcolumnheader.
    i'm using a itemrenderer to get rid of '1' but i need to make invisible the down arrow symbol too.
    sortExpertMode property is working for other columns but not for the column which i'm applying sort.
    Here is the code which disabling the number on columnheader:
    package
    import mx.controls.advancedDataGridClasses.AdvancedDataGridSortItemRenderer; 
    import mx.core.UITextField; 
    public class ADGSortItemRenderer extends AdvancedDataGridSortItemRenderer{
    public function ADGSortItemRenderer(){
    //TODO: implement function
    override protected function childrenCreated():void{ 
    super.childrenCreated(); 
    //Get reference to sort number text field
    var sortOrderTextField:UITextField = this.getChildAt(0) as UITextField; 
    if(sortOrderTextField != null){ 
    //Hide sort number text field
    sortOrderTextField.includeInLayout =
    false;sortOrderTextField.visible =
    false;}
    here is the image:
    is there any way to disable both the number(1) & down arrow??
    Thanks,
    Shravan P.

  • In AdvancedDataGrid - how can I stop sorting but keep order?

    I've seen this question a few times on the web and so far no one has come up with a workable solution.
    I'm using the sorting in ADG with an XMLListCollection bound as a dataprovider.  The user's are not happy because if the data changes in the column that's being sorted, the list resorts.  How can I remove the dynamic sorting but keep the order of the sort.  We want it to work like Excel where you do a sort but when you change the data it doesn't reorder the list.  What's the best, easiest way to do this?  My guess would be that I want to make a copy of the XMLListCollection but somehow save it in sorted order, then swap the copy in for the other XMLListCollection.  Not sure how to do that.  Thanks for any help.

    I've seen this question a few times on the web and so far no one has come up with a workable solution.
    I'm using the sorting in ADG with an XMLListCollection bound as a dataprovider.  The user's are not happy because if the data changes in the column that's being sorted, the list resorts.  How can I remove the dynamic sorting but keep the order of the sort.  We want it to work like Excel where you do a sort but when you change the data it doesn't reorder the list.  What's the best, easiest way to do this?  My guess would be that I want to make a copy of the XMLListCollection but somehow save it in sorted order, then swap the copy in for the other XMLListCollection.  Not sure how to do that.  Thanks for any help.

  • Showing sort icons without applying sort to the collection in AdvancedDataGrid

    Hi All,
    We have a scenario in our application where all the sorting has to be handled by the web services and the client just needs to show the sorted data in an Advanced Data Grid.
    The web services though returns details for the column on which it is being sorted and also the sort order i.e. ASC or DESC. So based on the same we need to simply show a ASC or DESC icon on the specified column header.
    We tried different options, but it seems the sort icons only show up when sorting is actually applied to the collection. But since the sorting is to be dealt with from the web services, it is not possible to apply sorting on the client side as it may result is differentiating data.
    So, can anyone please suggest a solution for this.
    Thanks,
    Eshaan

    Hi All,
    We have a scenario in our application where all the sorting has to be handled by the web services and the client just needs to show the sorted data in an Advanced Data Grid.
    The web services though returns details for the column on which it is being sorted and also the sort order i.e. ASC or DESC. So based on the same we need to simply show a ASC or DESC icon on the specified column header.
    We tried different options, but it seems the sort icons only show up when sorting is actually applied to the collection. But since the sorting is to be dealt with from the web services, it is not possible to apply sorting on the client side as it may result is differentiating data.
    So, can anyone please suggest a solution for this.
    Thanks,
    Eshaan

Maybe you are looking for

  • Best Views to Lovs

    Dear All sometimes i use View Objects based on EOS to be used in List of values, and sometimes i use View Objects in expert Mode (View Object without EO), which one better any why ? thanks

  • HT1977 How do I permanently Delete Apps on I-Pad 4 retina display

    How do I PERMANENTLY /delete/remove Apps I have purchased or trialed (subscription NOT  purchased at end of trial period)  or downloaded in error on my I-Pad 4 retina display.

  • Insert data from an tabular to a temp table and fetching a columns.

    Hi guys , I am working in apex 3.2 in which in a page i have a data's fom various tables and displays it in tabular form. Then i have to insert the tabular form data to a temp table and fetch the data from the temp table and insert into my main table

  • Checkout list for Post oracle upgrade

    Hi Experts, Please share the checkout list for post oracle upgrade. Thanks, Chandana

  • What SDK is Rome based on?

    Is this a Flex based project, or does Rome use a completely separate framework? Is there any plans for making the Rome components and / or framewokr available as an SDK?