It was for mx advanced datagrid but if it can help:
/**
* User: frederic.thomas
* Date: 22/06/11
* Time: 14:36
*/
package com.company.project.controls {
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.text.TextLineMetrics;
import com.company.project.event.AdvancedPaginatedDataGridSortEvent;
import com.company.project.model.PageManager;
import com.company.project.model.SortVO;
import mx.collections.SortField;
import mx.controls.AdvancedDataGrid;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.core.UIComponent;
import mx.events.AdvancedDataGridEvent;
/**
* Dispatched when a sort operation.
*
* @eventType
com.company.project.event.AdvancedPaginatedDataGridSortEvent.SORTING
*/
[Event(name="remoteSort",
type="com.company.project.event.AdvancedPaginatedDataGridSortEvent")]
public class AdvancedPaginatedDataGrid extends AdvancedDataGrid {
private var _pageManager:PageManager;
[Bindable]
public function get pageManager():PageManager {
return _pageManager;
}
public function set pageManager(value:PageManager):void {
_pageManager = value
}
[ArrayElementType("com.company.project.model.SortVO")]
private var _orderBy:Array;
public function get orderBy():Array {
return _orderBy;
}
public function set orderBy(value:Array):void {
_orderBy = value;
}
/**
* CONSTRUCTOR
*/
public function AdvancedPaginatedDataGrid() {
super();
}
protected var sortColumnSelectionEnded:Boolean;
/**
* @private
*/
override protected function
sortHandler(event:AdvancedDataGridEvent):void {
super.sortHandler(event);
_orderBy = [];
for each(var o:SortField in collection.sort.fields) {
_orderBy.push(new SortVO(o.name, (o.descending == false) ?
SortVO.DESCENDING : SortVO.ASCENDING));
}
dispatchEvent(new AdvancedPaginatedDataGridSortEvent(_orderBy));
}
/**
* Returns the header separators between column headers,
* and populates the <code>separators</code> Array with the separators
returned.
*
* @param i The number of separators to return.
*
* @param seperators Array to be populated with the header objects.
*
* @param headerLines The parent component of the header separators.
* Flex calls the <code>headerLines.getChild()</code> method internally
to return the separators.
*/
override protected function getSeparator(i:int, seperators:Array,
headerLines:UIComponent):UIComponent {
var sep:UIComponent = super.getSeparator(i, seperators,
headerLines);
sep.doubleClickEnabled = true;
// Add listener for Double Click
DisplayObject(sep).addEventListener(
MouseEvent.DOUBLE_CLICK, columnResizeDoubleClickHandler);
return sep;
}
/**
* @private
* Indicates where the right side of a resized column appears.
*/
private function columnResizeDoubleClickHandler(event:MouseEvent):void {
// check if the ADG is enabled and the columns are resizable
if (!enabled || !resizableColumns)
return;
var target:DisplayObject = DisplayObject(event.target);
var index:int = target.parent.getChildIndex(target);
// get the columns array
var optimumColumns:Array = getOptimumColumns();
// check for resizable column
if (!optimumColumns[index].resizable)
return;
// calculate the maxWidth - we can optimize this calculation
if (listItems) {
var len:int = listItems.length;
var maxWidth:int = 0;
for (var i:int = 0; i < len; i++) {
if (listItems[i][index] is IDropInListItemRenderer) {
var lineMetrics:TextLineMetrics =
measureText(IDropInListItemRenderer(listItems[i][index]).listData.label);
if (lineMetrics.width > maxWidth)
maxWidth = lineMetrics.width;
}
}
}
// set the column's width
optimumColumns[index].width = maxWidth + getStyle("paddingLeft") +
getStyle("paddingRight") + 8;
}
}
}
/**
* User: frederic.thomas
* Date: 21/06/11
* Time: 16:53
*/
package com.company.project.model {
[Bindable]
[RemoteClass(alias="com.company.project.model.Sort")]
public class SortVO {
public static const ASCENDING:int = 0;
public static const DESCENDING:int = 1;
public var field:String;
public var order:int;
public function SortVO(field:String = null, order:int = ASCENDING) {
this.field = field;
this.order = order;
}
}
}
/**
* User: frederic.thomas
* Date: 22/06/11
* Time: 15:52
*/
package com.company.project.event {
import flash.events.Event;
public class AdvancedPaginatedDataGridSortEvent extends Event {
public static const REMOTE_SORT:String = "remoteSort";
[ArrayElementType("com.company.project.model.SortVO")]
private var _orderBy:Array;
public function AdvancedPaginatedDataGridSortEvent(orderBy:Array,
bubbles:Boolean = true, cancelable:Boolean = false):void {
super(REMOTE_SORT, bubbles, cancelable);
this._orderBy = orderBy;
}
public function get orderBy():Array {
return _orderBy;
}
}
}
/**
* User: frederic.thomas
* Date: 16/04/11
* Time: 10:02
*/
package com.company.project.model {
import flash.utils.Dictionary;
[Bindable]
public class PageManager {
private var _allSelected:Boolean;
private var _inclusions:Dictionary = new Dictionary();
private var _exclusions:Dictionary = new Dictionary();
public var count:uint;
private var _selectedItemsLength:int;
public function get allSelected():Boolean {
return _allSelected;
}
public function set allSelected(value:Boolean):void {
_allSelected = value;
reset();
}
public function get inclusions():Dictionary {
return _inclusions;
}
public function set inclusions(inclusions:Dictionary):void {
_inclusions = inclusions;
}
public function set exclusions(exclusions:Dictionary):void {
_exclusions = exclusions;
}
public function get exclusions():Dictionary {
return _exclusions;
}
public function get selectedItemsLength():int {
return _selectedItemsLength;
}
public function set selectedItemsLength(value:int):void {
_selectedItemsLength = value;
}
public function select(id:*):void {
if (allSelected) {
if (delete(_exclusions[id]))
selectedItemsLength++;
} else {
_inclusions[id] = true;
selectedItemsLength++;
}
if (_selectedItemsLength == count)
allSelected = true;
}
public function deselect(id:*):void {
if (allSelected) {
_exclusions[id] = true;
selectedItemsLength--;
} else {
if (delete(_inclusions[id]))
selectedItemsLength--;
}
if (_selectedItemsLength == 0)
allSelected = false;
}
public function getItemList():Array {
var itemList:Array = new Array();
var dico:Dictionary = allSelected ? exclusions : inclusions;
for (var key:* in dico)
itemList.push(key);
return itemList;
}
private function reset():void {
inclusions = new Dictionary();
exclusions = new Dictionary();
selectedItemsLength = (_allSelected) ? count : 0;
}
}
}