FLEX DATAGRID 行上移/下移

来源:互联网 发布:js excel 导入 编辑:程序博客网 时间:2024/05/20 06:54

<?xml version="1.0" encoding="utf-8"?>  
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >  
<mx:Script>  
   <![CDATA[  
       import mx.collections.IList;    
       import mx.collections.ArrayCollection 

        [Bindable]
        public var employees:ArrayCollection = new ArrayCollection([
            {name: '丑哥哥01', phone: '13702023400', email: 'bjones@acme.com', status: 'I'},
            {name: '丑哥哥02', phone: '13702023401', email: 'ssmith@acme.com', status: 'I'},
            {name: '丑哥哥03', phone: '13702023402', email: 'bjones@acme.com', status: 'I'},
            {name: '丑哥哥01', phone: '13702023403', email: 'ssmith@acme.com', status: 'I'},                   
            {name: '丑哥哥05', phone: '13702023404', email: 'bjones@acme.com', status: 'I'},
            {name: '丑哥哥06', phone: '13702023405', email: 'ssmith@acme.com', status: 'I'},
            {name: '丑哥哥07', phone: '13702023406', email: 'bjones@acme.com', status: 'I'},
          
        ]);


          
       public function moveUp(event : MouseEvent) : void 
       {                   
          var i : int = peopleList.selectedIndex;  
          if(i >= 1&&peopleList.selectedItem)  
          {               
            IList(peopleList.dataProvider).addItemAt(peopleList.selectedItem,i-1);                    
            IList(peopleList.dataProvider).removeItemAt(i+1);  
            peopleList.selectedIndex = i;  
                      
           }  
       }  
          
       public function moveDown(event : MouseEvent) : void 
       {  
       var i : int = peopleList.selectedIndex;        
       if(i < (ArrayCollection(peopleList.dataProvider).length - 1) && peopleList.selectedItem)  
       {               
          IList(peopleList.dataProvider).addItemAt(peopleList.selectedItem,i + 2);                    
               IList(peopleList.dataProvider).removeItemAt(i);     
               peopleList.selectedIndex = i;               }              
       }                      
        ]]>  
    </mx:Script>  
    <mx:VBox horizontalAlign="center" x="618" y="176" height="264">     
    <mx:DataGrid id="peopleList"  x="198" y="66" width="302" dataProvider="{employees}" >  
        <mx:columns>  
           <mx:DataGridColumn dataField="name" headerText="Name"/>
                <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                <mx:DataGridColumn dataField="email" headerText="Email"/>
        </mx:columns>  
    </mx:DataGrid>  
    <mx:ControlBar width="298" autoLayout="true" horizontalAlign="right" height="26">  
        <mx:Button label="上移" click="moveUp(event)"/>  
        <mx:Button label="下移" click="moveDown(event)"/>  
    </mx:ControlBar>      
</mx:VBox>
</mx:Application> 

原创粉丝点击