FlexData 행 위아래로 이동, 위쪽, 아래쪽



private function orderDataGrid(evt:FilterOrderEvent):void
{
     var selectedObj:Object = dg.selectedItem;
     var selectIndex:int = dg.selectedIndex;
     var tempObj:Object;
     var dgData:ArrayCollection = ArrayCollection(dg.dataProvider);
     if(evt.movePosition == FilterOrderEvent.FILTER_MOVE_UP && selectIndex > 0)
     {
	// 
	selectedObj.ORDER = String(selectIndex);
	dgData.getItemAt(selectIndex - 1).ORDER = String(selectIndex+1);

	dgData.addItemAt(selectedObj,selectIndex - 1);
	dgData.removeItemAt(selectIndex + 1);
	dg.selectedIndex = selectIndex;
					
	}
	else if(evt.movePosition == FilterOrderEvent.FILTER_MOVE_DOWN && selectIndex < dgData.length -1)
	{
	// 
	selectedObj.ORDER = String(selectIndex+2);
	dgData.getItemAt(selectIndex + 1).ORDER = String(selectIndex+1);

	dgData.addItemAt(selectedObj,selectIndex + 2);                    
	dgData.removeItemAt(selectIndex);
	dg.selectedIndex = selectIndex;          

	}
	else if(evt.movePosition == FilterOrderEvent.FILTER_MOVE_TOP && selectIndex > 0)
	{
	// 
	for(var i:int = 0; i <= selectIndex; i++)
	{
		tempObj = dgData.getItemAt(i);
		tempObj.ORDER = String(i+2);
	}
	selectedObj.ORDER = "1"
	dgData.addItemAt(selectedObj,0);
	dgData.removeItemAt(selectIndex + 1);
	dg.scrollToIndex(0);
	dg.selectedIndex = 0;

	}
	else if(evt.movePosition == FilterOrderEvent.FILTER_MOVE_BUTTOM && selectIndex  < (dgData.length - 1))
	{
	// 
	for(var j:int = selectIndex; j < dgData.length; j++)
	{
		tempObj = dgData.getItemAt(j);
		tempObj.ORDER = String(j);
	}
	selectedObj.ORDER = String(dgData.length);

	dgData.addItemAt(selectedObj,dgData.length);                    
	dgData.removeItemAt(selectIndex);   
	dg.scrollToIndex(dgData.length-1);
	dg.selectedIndex = dgData.length-1; 
	}
}


좋은 웹페이지 즐겨찾기