In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside).
protected function headerReleaseHandler(event:DataGridEvent):void {
event.preventDefault();
var c:DataGridColumn = columns[event.columnIndex];
var index:int = c.dataField as int;
var isDesc = c.sortDescending;
if(index == _lastSortIndex)
{
isDesc = !this._lastSortDesc;
}
var pageSort:PageSort = new PageSort(index,isDesc,this);
pageSort.onPageSort();
this._lastSortIndex = index;
this._lastSortDesc = isDesc;
}
public class PageSort
{
private var model:MyModelLocator = MyModelLocator.getInstance();
private var service:Object;
private var sortIndex:int;
private var sortDesc:Boolean;
private var pagedDG:PaginatedDataGrid;
public function PageSort(sortIndex:int,sortDesc:Boolean,pagedDG:PaginatedDataGrid)
{
service = ServiceLocator.getInstance().getRemoteObject("localInfo");
this.sortIndex = sortIndex;
this.sortDesc = sortDesc;
this.pagedDG = pagedDG;
}
public function onPageSort():void
{
var call:Object = service.GetPageSort(sortIndex,sortDesc);
call.addResponder(new AsyncResponder(onSortResultHandler,onSortFaultHandler));
}
public function onSortResultHandler(evt:Object,token:Object = null):void
{
pagedDG.dataProvider = evt.result.serverInfo.initialData as Array;
}
public function onSortFaultHandler(evt:FaultEvent,token:Object = null):void
{
Alert.show('Error,'Error in sorting!');
}
}
This works perfectly, except that the arrows that indicate sorting isn't shown. How can I accomplish that?
Thanks!/Shuo