How to sort a flex datagrid according to multiple columns?

The best answer I've found so far is to capture the headerRelease event when the user clicks: mx:DataGrid id="theGrid" x="61" y="55" width="466" height="317" headerRelease="onHeaderRelease(event) The event handler can then apply a sort order to the data: private var lastIndex:int = -1; private var desc:Boolean = false; public function onHeaderRelease(evt:DataGridEvent):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, false, desc ) ); if( evt.

DataField! = "A" ) fields. Push( new SortField("A", false, desc) ); if( evt.

DataField! = "B" ) fields. Push( new SortField("B", false, desc) ); if( evt.

DataField! = "C" ) fields. Push( new SortField("C", false, desc) ); srt.

Fields = fields; var ar:ArrayCollection = this.theGrid. DataProvider as ArrayCollection; ar. Sort = srt; ar.refresh(); } However this approach has a well-known problem, which is that the column headers no longer display little arrows to show the sort direction.

This is a side-effect of calling evt.preventDefault() however you must make that call or else your custom sort won't be applied.

The best answer I've found so far is to capture the headerRelease event when the user clicks: The event handler can then apply a sort order to the data: private var lastIndex:int = -1; private var desc:Boolean = false; public function onHeaderRelease(evt:DataGridEvent):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, false, desc ) ); if( evt.

DataField! = "A" ) fields. Push( new SortField("A", false, desc) ); if( evt.

DataField! = "B" ) fields. Push( new SortField("B", false, desc) ); if( evt.

DataField! = "C" ) fields. Push( new SortField("C", false, desc) ); srt.

Fields = fields; var ar:ArrayCollection = this.theGrid. DataProvider as ArrayCollection; ar. Sort = srt; ar.refresh(); } However this approach has a well-known problem, which is that the column headers no longer display little arrows to show the sort direction.

This is a side-effect of calling evt.preventDefault() however you must make that call or else your custom sort won't be applied.

I tried your code in my apps and it worked! Using Flex 3, it displays the little arrow that shows the sort direction. Thanks, Arnold.

This should have been a comment to the answer and not posted AS an answer. – the_new_mr Oct 20 at 11:36.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions