flex DataGridColumn 固定序号

<?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.ArrayCollection;
    	     private var employees:ArrayCollection = new ArrayCollection([
    	     												
    	     												{name:"张三",phone:"123456",email:"[email protected]"},
    	     												{name:"李四",phone:"1234567",email:"[email protected]"},
    	     												{name:"王五",phone:"1234568",email:"[email protected]"},
    	     												{name:"刘六",phone:"1234569",email:"[email protected]"}
    	     											]);
    	
		    //固定序号labelFunction函数
		   private function RowNum(oItem:Object,iCol:int):String
		   {
//		      var iIndex:int = employees.getItemIndex(oItem) + 1;   //在当前集合中那个位置(便于自己理解,可能解释不准确)
			  var iIndex:int = employees.source.indexOf(oItem) + 1; //在原来集合中那个位置(便于自己理解,可能解释不准确)
		      return String(iIndex);
		   }
    	]]>
    </mx:Script>
    <mx:DataGrid id="dg" color="0x323232" width="100%" rowCount="5" dataProvider="{employees}">
          <mx:columns>
          		<mx:DataGridColumn id="num" dataField="orderId" headerText="序号" width="50" labelFunction="RowNum" sortable="false"/>
                <mx:DataGridColumn dataField="name" headerText="姓 名"/>
                <mx:DataGridColumn dataField="phone" headerText="电 话"/>
                <mx:DataGridColumn dataField="email" headerText="邮 箱"/>
          </mx:columns>
    </mx:DataGrid>
</mx:Application>

你可能感兴趣的:(flex DataGridColumn 固定序号)