SortCompareFunction

Hi,
Is there a way to sort a date field in a data grid that is
using a labelfunction to get the date value. How to use
sortCompareFunction with that?
Thanks

Sure:
import mx.collections.Sort;
var s:Sort = new Sort();
sort.fields = [ new SortField("DateStarted") ];
sort.compareFunction = function(a:Object, b:Object,
fields:Array = null ) {
if( a.DateStarted.time < b.DateStarted.time ) return -1;
else if( a.DateStarted.time > b.DateStarted.time ) return
1;
else return 0;
Test.sort = s;
Test.refresh(); // important to do this
You need to have your own compareFunction because Date is not
a String nor a Number, although the time property is a Number and
can be compared.
An alternative is to start the time of the Date (milliseconds
since Jan 1970) and use the labelFunction to convert it back into a
Date and format it. If you do this then you do not need the sort's
compareFunction.

Similar Messages

  • SortCompareFunction not working with AdvancedDataGrid

    Hi,
    There seems to be an issue with sortCompareFunction in the
    AdvancedDataGrid. My sort function is simply not
    triggered at all when I click on the header (sortable is set
    to true).
    Here's the relevant code, is there a problem ?

    Hi,
    Please try the given code which is working fine.
    I have attached the sortCompareFunction for second column
    i.e "Actual" column. Click on the header of this column to see the
    trace statements in the console.

  • Why is sortCompareFunction called when clicking checkbox on non-sortable column?

    Hello,
    I have a datagrid that contains three static DataGridColumn columns.  The first column uses a checkbox item renderer whose sortable property is set to false:
    <mx:DataGridColumn
    width="100"
    sortable="false"
    itemRenderer="com.mycomponent.CheckBoxItemRenderer" />
    On creation complete, a fourth column is added dynamically to the datagrid, through ActionScript, and several of its properties are set, like so:
    var dgc : DataGridColumn = new DataGridColumn();
    dgc.headerText = someAttribute.name;
    dgc.itemRenderer = new ClassFactory(ProductResultItemRenderer);
    dgc.sortCompareFunction = attributeCompareFunction;
    Everything is rendered just fine.  If I sort the datagrid items by clicking the column header of the second or third columns (these are the static columns that use Flex's default sort function) and then click on any of the items' checkboxes, there are no issues.  However, if I sort the items by clicking on the header of the dynamically-added fourth column and then click on any of the items' checkboxes, the results are partially re-sorted.  Setting a breakpoint in my attributeCompareFunction method, any time I click a checkbox in this use case, this compare function is called.
    Can someone shed some light on why this function is invoked in this last use case, especially when performing a non-sortable event (clicking on a checkbox)?
    Thanks,
    -Jose

    Hi Alex,
    I set a breakpoint in the sortCompareFunction, but I'm unable to determine what is calling it.  Here is the call stack:
    Main Thread (Suspended)
    Function/<anonymous>
    mx.collections::SortField/http://www.adobe.com/2006/flex/mx/internal::internalCompare
    mx.collections::Sort/internalCompare
    mx.collections::Sort/findItem
    mx.collections::ListCollectionView/http://www.adobe.com/2006/flex/mx/internal::findItem
    mx.collections::ListCollectionView/addItemsToView
    mx.collections::ListCollectionView/moveItemInView
    mx.collections::ListCollectionView/handlePropertyChangeEvents
    mx.collections::ListCollectionView/listChangeHandler
    flash.events::EventDispatcher/dispatchEventFunction [no source]
    flash.events::EventDispatcher/dispatchEvent [no source]
    mx.collections::ArrayList/internalDispatchEvent
    mx.collections::ArrayList/itemUpdateHandler
    flash.events::EventDispatcher/dispatchEventFunction [no source]
    flash.events::EventDispatcher/dispatchEvent [no source]
    com.my.package.models::ProductVO/dispatchEvent [no source]
    com.my.package.models::ProductVO/set compare [no source]
    com.my.package.components::CheckBoxItemRenderer/onChange
    com.my.package.components::CheckBoxItemRenderer/___CheckBoxItemRenderer_CheckBox1_change
    flash.events::EventDispatcher/dispatchEventFunction [no source]
    flash.events::EventDispatcher/dispatchEvent [no source]
    mx.core::UIComponent/dispatchEvent
    spark.components.supportClasses::ToggleButtonBase/buttonReleased
    spark.components.supportClasses::ButtonBase/mouseEventHandler
    The event dispatched by "ProductVO/dispatchEvent" is of type "mx.events.PropertyChangeEvent", which is OK since the "compare" property was updated.  However, later in the call stack, the "ArrayList" object fires an "internalDispatchEvent" of type "mx.events.CollectionEvent", which is an "update" event.  Looking at the rest of the call stack, this is the event that leads to the re-sort.
    Is there any way to prevent this CollectionEvent event from firing and, if so, how?
    Thanks,
    -Jose

  • SortCompareFunction question

    how would i specify the datacolumn name that i want to sort based on the one the user clicked? i am able to do this only by strong typing the datafield but i want to be able to just put the sortCompareFunction on every dollar value column I have in the DB and have it know which one the user is trying to sort without hard typing it:
    for example:
    I have an actionscript function like this:
    private function price_sortCompareFunc(itemA:Object, itemB:Object):int { 
    return ObjectUtil.numericCompare(itemA.TOTAL_LP, itemB.TOTAL_LP);}
    and datagrid with a datacolumn and sortCompareFunction like this:
    <mx:DataGridColumn  headerText="List Price" sortCompareFunction="{price_sortCompareFunc}" labelFunction="{price_labelFunc}" dataField="TOTAL_LP" width="110" textAlign="right"/>
    see how I am specifically calling out TOTAL_LP in the returned variable in the function? how can i have the function dynamically plug this in?
    i've tried adding column:DataGridColumn after the itemB:Object in the function but get the expecting 3 parameters and got 2 error. but notice how the sort compare function never needs to reference the 2 elements anyway... why is that?

    I would subclass DataGridColumn and add the sortCompareFunction to the
    subclass.

  • SortcompareFunction is not working properly for more than 1 column in advanced datagrid

    Hi Guys,
    I am using an advanced datagrid with groupingCollection.
    I have more than 1 grouped column. How ever I am using 2 sort compare function to sort date and time.
    The problem is when I am trying to sort date its workinf properly then when I jump to time column its not working and sorting few rows only inside the  column but not the entire column. samething happen when I sort time first and the date is not sorting.
    any help will be really appriciable .
    Thanks in advance.

    In our application we tend to use views to return appropriate values for a particular user.
    For example (we do building inspections) the publication item sql is like
    select * from inspection_sites where id in (select site_id from v_pda_bi_sites where bi_id=:bi_id)
    The view acts like a dynamic parameter table (in this cases looks at experience level, status of sites, and responsibility allocations). Once the driving views are tuned this works quite efficiently, and as the dependant tables for the publication item automatically includes all of the tables in the driving view, the object gets refreshed if there is any change to any of them, even if the site details themselves have not changed

  • Problem with printing after migrating from 3.5 to 4.1

    Hello everyone,
    I'm currently working on an application that was recently migrated (by someone else) from Flex 3.5 to Flex 4.1 and I discovered the printing doesn't work properly anymore. So I tried to find out what the problem was and after many tries, I came to the conclusion that the problem was within the following line:
    printJob.addObject(myPrintView,FlexPrintJobScaleType.MATCH_WIDTH);
    (Of course "myPrintView" is not the real name used in the app but that's not important)
    I searched on the Internet and this line is supposed to work in 4.1, isn't it? However, the printed version cuts my PrintAdvancedDataGrid approximately in half. I tried to change the width property from myPrintView but the grid is still cut at the same place, its cells are just distorted.
    FYI, you can find a part of the code right here:
    var printJob:FlexPrintJob = new FlexPrintJob();
                        if (printJob.start()) {
         //A lot of code to build the print view
    myPrintView.width=1280;
    printJob.addObject(myPrintView,FlexPrintJobScaleType.MATCH_WIDTH);
    printJob.send();
    myPanel.removeChild(myPrintView);
    Any help would be appreciated.
    Regards,
    Gudril

    While looking for a solution on the Internet I found some people having troubles because of the structure of their AdvancedDataGrid. My problem doesn't come from any example I've seen but maybe it's still linked to that, so here's an AdvancedDataGrid that's being printed in my app:
                                                    <mx:PrintAdvancedDataGrid dataProvider="{dataRayon}" sortExpertMode="true" id="dataGridRayon" width="100%" itemClick="dispatchEvent(new KpiEvent(DATAGRID_RAYON_CLICK,event));" itemDoubleClick="dispatchEvent(new KpiEvent(DATAGRID_RAYON_CLICK,event));" creationComplete="resizeGridRayon();" >
                                                      <mx:columns>
                                                                <mx:AdvancedDataGridColumn id="rownumRayon"  width="25"  sortable="false" labelFunction="getRowNumRayon" fontWeight="bold"/>
                                                                <mx:AdvancedDataGridColumn id="rayonCoRgrp" textAlign="center" width="75" headerText="{resourceManager.getString('rentabilitePanel', 'CODE')}" dataField="co_rgrp_produits" />
                                                                <mx:AdvancedDataGridColumn textAlign="left" width="240" headerText="{resourceManager.getString('rentabilitePanel', 'SOUS_SECTEURS')}" dataField="libelle" id="hTDataGridRayon" />
                                                                <mx:AdvancedDataGridColumn id="rayonMeVenteHt" textAlign="right" width="100" headerText="{resourceManager.getString('rentabilitePanel', 'MONTANT_VENTE_HT')}" dataField="meVenteHt" formatter="{currencyFormatter}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'meVenteHt');}}"  />
                                                                <mx:AdvancedDataGridColumn id="rayonMargeAvtDem" textAlign="right" width="75" headerText="{resourceManager.getString('rentabilitePanel', 'MARGE_AVT_DEM')}" dataField="margeAvtDem" formatter="{currencyFormatter}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAvtDem');}}"  />
                                                                <mx:AdvancedDataGridColumn id="rayonPMargeAvtDem" textAlign="right" width="80" headerText="{resourceManager.getString('rentabilitePanel', 'POUR_MARGE_AVT_DEM')}" dataField="margeAvtDemP" formatter="{pourcentageFormatterFloat}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAvtDemP');}}"  />
                                                                <mx:AdvancedDataGridColumn id="rayonDemarqueHt" textAlign="right" width="100" headerText="{resourceManager.getString('rentabilitePanel', 'DEMARQUE_HT')}" dataField="demarque" formatter="{currencyFormatterFloat1Dec}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'demarque');}}"  />
                                                                <mx:AdvancedDataGridColumn id="rayonPDemarqueHt" textAlign="right" width="85" headerText="{resourceManager.getString('rentabilitePanel', 'POUR_DEMARQUE_HT')}" dataField="demarqueP"  formatter="{pourcentageFormatterFloat}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'demarqueP');}}"  />
                                                                <mx:AdvancedDataGridColumn id="rayonMargeAprDem" textAlign="right" width="100" headerText="{resourceManager.getString('rentabilitePanel', 'MARGE_APR_DEM')}" dataField="margeAprDem" formatter="{currencyFormatter}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAprDem');}}"  />
                                                                <mx:AdvancedDataGridColumn id="rayonPMargeAprDem" textAlign="right" width="115" headerText="{resourceManager.getString('rentabilitePanel', 'POUR_MARGE_APR_DEM')}" dataField="margeAprDemP" formatter="{pourcentageFormatterFloat}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAprDemP');}}"  />
                                                      </mx:columns>
                                            </mx:PrintAdvancedDataGrid>
    I also realised I wasn't very clear on the outcome of my doPrint() function. When I said the grid was cut in half, I was talking about half the columns not showing on the printed version, not half the rows. Actually even a column being cut in half. I hope these precisions made my problem a bit clearer and somebody will be able to help me in any way (even just hints).
    Thanks for your help.
    Regards,
    Gudril

  • What is the best way to create CRUD datagrids

    What is the best way to create CRUD datagrids that tell CF
    components to update sql tables. I find that I'm having to vreate
    all these columns with custom properites and its a bit of a chore:
    <mx:DataGridColumn id = "NatWest" dataField="NatWest"
    headerText="NatWest" editable="false"
    wordWrap="true"
    textAlign="right"
    headerStyleName="centered"
    labelFunction="price_labelFuncNatWest"
    sortCompareFunction="price_sortCompareFunc">
    I don't really want to use any wizards as I want control over
    my code.

    Hi Saythj,
    When mentioning "a database schema from XML", do you mean the
    XML Schema Collections? If that is what you mean, when trying to import XML files of the same schema type, you may take the below approach.
    Create an XML Schema Collection basing on your complex XML, you can find
    many generating tools online to do that.
    Create a Table with the above created schema typed XML column as below.
    CREATE TABLE youTable( Col1 int, Col2 xml (yourXMLSchemaCollection))
    Load your XML files and try to insert the xml content into the table above from C# or some other approaches. The XMLs that can't pass the validation fail inserting into that table.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Keep sorting and sort arrows after datagrid dbprovider changed

    I followed this tutorial http://justinjmoses.wordpress.com/2008/06/26/flex-keeping-the-sort-on-a-datagrid-when-you- change-the-dataprovider/
    created listeners
    that keeps old sorting of datagrid after dataprovider changed, but displaying sort arrow on the wrong column(always the 1st column), how do I fix it?
                       //constructor
              public function FilterDatagrid()
                   super();
                   addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, onDataGridDataChange, false, 0, true);
              private var currentSort:mx.collections.Sort;
              private function onDataGridDataChange(evt:CollectionEvent):void
                   //get the new data collection
                   var ac:ArrayCollection = this.dataProvider as ArrayCollection;
                   //attach the collection change event
                   ac.addEventListener(CollectionEvent.COLLECTION_CHANGE, onCollectionChanged,false,0,true);
                   //if a sort was in place before the data was changed, make sure you apply the sort to this new data
                   if (currentSort != null)
                        ac.sort = currentSort;
                        ac.refresh();
              private function onCollectionChanged(evt:CollectionEvent):void
                   if (evt.kind == CollectionEventKind.REFRESH)
                        var ac:ArrayCollection = evt.currentTarget as ArrayCollection;
                        currentSort = ac.sort;

    the datagrid uses XML as dataprovider and uses labelFunction and sortCompareFunction on each column, not sure if it matters

  • HP QTP10 cannot read Automation values of Advanced DataGrid

    Hi everyone,
    We're an Automation functional testing team, testing a flex application with HP QTP v10. So far we've successfully automated many parts of the application. Now, we're struck at a serious issue.
    The issue is QTP cannot read automation values specified for an Advanced Datagrid (ADG).
    While trying to read row data of the ADG, the automation name of QTP shows like,
    "lblData | someGroup |  | ** |  |  |  |  |  |  |  |  |  | lblData"
    The screenshot of Object Spy while spying ADG is also attached.
    Other than the Automation Index, we are not able to populate any automation values of a row data.
    The ADG is a custom one. Our development team has customized it in some way, and we dont have access to the code. They are using an External renderer or Custom renderer to render values into the column.
    As there is no possiblity for value-based recording, we tried to access the ADG with index-based recording. Then, we 're able to perform operations like Click, but cannot read contents of the row/cell.
    We're using:
    HP Quick TestProfessional v10.0
    Flex plugin 4.5
    Internet Explorer 7
    Flash Player v10
    Our Questions are:
    How to get automation values for these custom ADG?
    Is there any other possible ways to access the custom ADG components other than these automation values?
    Do we need any patches/plugin upgradation to perform this?
    Is there any other tools in market that can recognize and access these custom ADGs?
    Without these automation values we're unable to proceed further work. Any replies/comments/help are welcome.
    Thank you!

    A sortCompareFunction would look something like:
    Function sortWithNullAtEnd(a:Object, b:Object, field:Array = null):int
        if (a.fieldName == null && b.fieldName == null) return 0;
        if (a.fieldName == null) return 1;
        if (b.fieldName == null) return –1;
        if (a.fieldName < b.fieldName)
            return –1;
        if (a.fieldName > b.fieldName)
            return 1;
        return 0;
    Note that this sort would be unstable so you might be better off using a second field to get stability.

  • Editable DataGrid With DateField

    I'm new to flex and struggling with the editable DataGrid. I
    have a DataGrid with an ItemRenderer that outputs a DateField. I
    can't figure out how to get the new value of the DateField after
    the edit.
    Here is my DataGrid (the endDate column):
    <mx:DataGrid id="allHistoryGrid"
    dataProvider="{allEntries}" height="313" width="782" y="-4"
    itemEditEnd="saveGridChange(event)" editable="true">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn dataField="dietDescription"
    headerText="Diet"/>
    <mx:DataGridColumn dataField="allergyDescription"
    headerText="Allergy"/>
    <mx:DataGridColumn dataField="labDescription"
    headerText="Lab"/>
    <mx:DataGridColumn dataField="labResult" width="50"
    headerText="Result" itemRenderer="LabResultItemRenderer"/>
    <mx:DataGridColumn dataField="medicationDescription"
    headerText="Medication"/>
    <mx:DataGridColumn dataField="height" width="65"
    headerText="Height" itemRenderer="HeightItemRenderer"/>
    <mx:DataGridColumn dataField="weight" headerText="Weight"
    itemRenderer="WeightItemRenderer"/>
    <mx:DataGridColumn dataField="bmi" width="35"
    headerText="BMI" itemRenderer="BmiItemRenderer"/>
    <mx:DataGridColumn dataField="circumference" width="45"
    headerText="Circ." itemRenderer="CircumferenceItemRenderer"/>
    <mx:DataGridColumn headerText="Start Date" width="75"
    sortCompareFunction="startDateSortCompare">
    <mx:itemRenderer>
    <mx:Component>
    <mx:VBox clipContent="false">
    <mx:DateFormatter id="dateFormatter"
    formatString="MM/DD/YYYY"/>
    <mx:Text width="100"
    text="{dateFormatter.format(data.startDate)}"/>
    </mx:VBox>
    </mx:Component>
    </mx:itemRenderer>
    </mx:DataGridColumn>
    <mx:DataGridColumn dataField="endDate" width="45"
    headerText="End Date" itemRenderer="EndDateItemRenderer"
    rendererIsEditor="true"/>
    <mx:DataGridColumn id="deleteEntry" width="50"
    textAlign="center"
    headerText="Delete" sortable="false"
    itemRenderer="DeleteItemRenderer"/>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    Here is my itemRenderer:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    paddingLeft="16" horizontalAlign="center">
    <mx:DateFormatter id="dateFormatter"
    formatString="MM/DD/YYYY"/>
    <mx:DateField x="16" y="67" id="AllHistoryEndDate"
    text="{dateFormatter.format(data.endDate)}"/>
    </mx:VBox>
    How do I get the new value in the saveGridChange function?
    private function saveGridChange(event:DataGridEvent):void {

    That gives me this error:
    TypeError: Error #1034: Type Coercion failed: cannot convert
    EndDateItemRenderer@51a70a1 to mx.controls.TextInput.

  • Passing Optional Parameter Via Extended Class Constructor

    Following is a snippet of code I copied and have a question about when extending DataGridColumn class to sort numeric for colums that have numeric values:
    CustomAdvancedDataGridColumn(columnName:String=null,numeric:Object=null)
    super(columnName);
    initCompare(numeric);
    function initCompare(numeric:Object):void
    if (numeric == NUMERIC) {
    sortCompareFunction = numericCompare;
    The extended class is supposed to receive variable "numeric" type Object in the constructor which is then supposed to be used in the initCompare function to determine if a column contains numeric values.  This code didn't work for me as numeric variable remains null.  To get it working I added a new public static const and private propery "numeric" and obtained it with get() set() to see if should the column should sort numeric.  This works but you have to set the property in the extended datagrid column FLEX  tag.
    My question is how is the variable numeric in the code snippet above supposed to get it's new data for the initCompare function?  I can't get it to be anything other than null.
    Thanks for any insights...I'm new to FLEX.
    Jason

    Still searching for a solution.
    Please note, that I'm using the syntax described in
    <a href="http://help.sap.com/businessobject/product_guides/boexir31/en/xi3-1_url_reporting_opendocument_en.pdf">http://help.sap.com/businessobject/product_guides/boexir31/en/xi3-1_url_reporting_opendocument_en.pdf</a>
    on page 65.
    So did I get anything wrong? Help would be really appreciated, also Workarounds if there's no solution for the problem.

  • Putting a combobox in an advanceddatagrid

    I know that I was able to do this in Flex 3, but for some reason I keep getting errors in Flex 4 by trying to put a ComboBox into an advancedDataGrid. I basically want the datagrid to be completely independent of the list of objects that are in the datagrids dataProvider.
    Right now I have something that looks like this:
    <ns:XX_DataGrid id="serversDataGrid" left="3" right="3" bottom="4"  allowMultipleSelection="false" selectable="false" dataProvider="{dModel.serversSelectedForDeployment}">
                    <ns:groupedColumns>
                        <ns:XX_DataGridColumn headerText="{l.Servers_ServiceTag}" dataField="SvcTag" width="118" sortCompareFunction="onSvcTagSort"/>
                        <ns:XX_DataGridColumn headerText="{l.Servers_Model}" dataField="Model" width="110" sortCompareFunction="onModelSort"/>
                        <mx:XX_DataGridColumn headerText="{l.Profile}"
                                itemRenderer="com.dell.pg.spectre.components.itemRenderers.ComboBoxItemRenderer"
                                 />
                    </ns:groupedColumns>
                </ns:XX_DataGrid>
    The item renderer looks like this:
    <?xml version="1.0" encoding="utf-8"?>
    <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    autoDrawBackground="true">
        <s:Label text="{data}"/>
    </s:MXDataGridItemRenderer>
    I've tried this several ways. Anyone know how to get this to work?

    Your renderer should have a combobox instead of the label.
    <?xml version="1.0" encoding="utf-8"?>
    <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    autoDrawBackground="true">
       <s:Label text="{data}"/> - here you need the combobox and will have to override the set data method.
    </s:MXDataGridItemRenderer>

  • 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

  • Cannot determine comparator for Sortfield

    I have a DataGrid that gets its data from an HttpService. If
    the first row of the data from the http request has a null value
    for a given field, I get the "Cannot determine comparator for
    Sortfield" error.
    I think the simplest workaround would be to specify the data
    type for each DataGridColumn. I see that the DataGridColumn objects
    can have a sortCompareFunction. I don't want to write my own custom
    comparators. I assume that the built-in comparators will do just
    fine.
    Suppose my MXML code looks something like this...
    <mx:DataGrid>
    <mx:columns>
    <mx:DataGridColumn headerText="My String"
    dataField="name" sortCompareFunction="???"/>
    <mx:DataGridColumn headerText="My Integer" dataField="ss"
    sortCompareFunction="???"/>
    <mx:DataGridColumn headerText="My Float" dataField="gpa"
    sortCompareFunction="???"/>
    <mx:DataGridColumn headerText="My Date"
    dataField="birthdate" sortCompareFunction="???"/>
    </mx:columns>
    </mx:DataGrid>
    What values would I use for the sortCompareFunctions in order
    to use the built-in comparators for the string, int, float and date
    types, respectively?

    One trick that I've used in the past (which wont really give
    you type specific ability) is to check the returned data prior to
    assigning it as a dataProvider. In my case the data is xml based
    son I don't get nodes, but possible missing elements all together.
    I check for their existance for each row (in your case test for
    null) then assign a default value (-1 for int, 6/6/2006 for date
    etc...). After populating the 'voids' in my data I assign it as the
    dataProvider in ActionScript.
    To get more type specifc, you may want to look into using a
    data model and check out the validator classes.

  • Flex 4, datagrid, checkboxes, and the impossible dream?

    I want to build a datagrid that has a column with checkboxes so the user can select a single record or multiple records (for deletion, for exporting, for whatever). But I also want to enable the user to click on anywhere in the row other than the checkbox to open a record for editing. I know how to do one or the other function, but I haven't been smart enough to figure out how to combine the functions with Flex 4. Is it possible?
    I see this sort of functionality in my gmail account - I can click on checkboxes to select items for delete *and* I can click on any item to open it for reading, etc. The item doesn't open when I click on the checkbox. I see lots of posts discussing checkboxes in datagrids. I've studied Alex's Flex Closet post at http://blogs.adobe.com/aharui/2010/01/checkboxes_in_datagrid_with_ch.html most closely. Can anyone point me in the right direction?
    TIA!!!

    Interesting. For a workaround, does it work for you if you wrap the caselessSortForField() in some curly quotes (ie: use databinding)?
    <mx:DataGridColumn dataField="index"
            sortCompareFunction="{caselessSortForField('index')}" />
    It worked for me locally using my simple test case and a nightly Flex 4.1 SDK.
    Peter

Maybe you are looking for