开发者

Sort Columns in advancedDataGrid

I'm making an application where I displa开发者_StackOverflowy an AdvanvedDataGrid with one column with dates(in format DD/MM/YYYY) and another with datetimes (in format HH:MM). I'd like to sort dates according with the datetimes as well(just clicking in the header of the column), there is an examplen of the expected behaviour:

02/02/2011 | 10:42

03/02/2011 | 09:45

02/02/2011 | 11:45

03/02/2011 | 11:30

So clicking in the "date" header sort the dates taking into account the datetimes:

02/02/2011 | 10:42

02/02/2011 | 11:45

03/02/2011 | 09:45

03/02/2011 | 11:30

I'm trying using the AdvancedDataGridColumnGroups with it does not work, any suggetions or ideas to start working?

Thanks in advance

EDIT: This is the code for my adg:

<mx:AdvancedDataGrid id="myADG" width="100%" height="100%" color="0x323232"
    dataProvider="{_currentDatosBusqueda}" verticalScrollPolicy="auto"
    fontSize="10" fontFamily="Arial" fontStyle="normal" fontWeight="bold" doubleClickEnabled="true"
    itemDoubleClick="dobleClickFilaDataGridBusqueda(event);" useRollOver="true">        


<mx:columns>
    <mx:AdvancedDataGridColumn headerText="Paciente ID" dataField="patientID"  paddingRight="0" resizable="false"/>
    <mx:AdvancedDataGridColumn headerText="Apellidos y nombre de paciente" dataField="patientName" resizable="false"/>
    <mx:AdvancedDataGridColumn headerText="Fecha del estudio" dataField="studyDate"  paddingRight="0" textAlign="right" resizable="false"/>
    <mx:AdvancedDataGridColumn headerText="Hora del estudio" dataField="studyTime"  paddingRight="0" textAlign="right" resizable="false"/>
    <mx:AdvancedDataGridColumn headerText="Accesion Number" dataField="accesionNumber" paddingRight="0" resizable="false"/>

</mx:columns>

_currentDatosBusqueda is an arraycollection I receive from the Server (with the correct format of dates and datetime).


Supply full date into date column, but render only date part with labelFunction. For label function, create formatDate like that:

import mx.formatters.DateFormatter;

private var formatter:DateFormatter = new DateFormatter();
//somewhere in init function
formatter.formatString = "DD/MM/YYYY";

private function formatDate(item:Date, column:DataGridColumn):String {
    return formatter.format(item);
}

Sorting on this column should take into account full date.

Edit: OK, data is formatted on server. But nothing prevents you from combining it into full date/time object and use it on two columns with corresponding labelFunctions. Simple and robust.


Finally I can sort the columns of my advandedDataGrid setting the compare function to the HeaderRelease property but I still having an error cause the little arrow dont show the sort direction, how can I set it?

My headerRelease function is:

public function onHeaderRelease(evt:AdvancedDataGridEvent):void
        {
            evt.preventDefault();

            var srt:Sort = new Sort();
            var fields:Array = new Array();

            if( evt.columnIndex == lastIndex )
            {
                desc = !desc;
            }
            else
            {
                desc = false;
                lastIndex = evt.columnIndex;
            }

            fields.push( new SortField( evt.dataField, true, desc ) );
            if( evt.dataField != "studyDate" && evt.dataField !="studyTime" )
                fields.push( new SortField("studyDate", true, true) );
            if( evt.dataField != "studyTime" )
                fields.push( new SortField("studyTime", true, false) );

            srt.fields = fields;

            var ar:ArrayCollection = myADG.dataProvider as ArrayCollection;
            ar.sort = srt;
            ar.refresh();
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜