FlexData 行 上移 下移动,置顶,置底
程序员文章站
2023-12-26 15:36:27
...
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;
}
}