Flex 행 번호 생성

9793 단어 Flex
private function formatIndexNumber(item:Object, colum:Object):String {      return indexNumLabelFun(item, colum.mx_internal::owner);  }
 public function indexNumLabelFun(value:Object, dataGrid:Object):String {     var arr:Array = (PageDataGrid.dataProvider as ArrayCollection).toArray();     var indexNum: int = (arr.indexOf(value) + 1);         Alert.show(indexNum.toString(), "prompt");     data.abc = indexNum.toString();          return indexNum.toString();}
----------------------------------------------------------------------------------------------------------------------------

public function genrowno(ob:Object):String {  return String(PageDataGrid.dataProvider.getItemIndex(ob) + 1);    }
--------------------------------------------------------------------------------------------------------------------------------
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"  horizontalAlign="center">
    <mx:Script>
        <![CDATA[
            import mx.controls.AdvancedDataGrid;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            
            override public function set data(value:Object):void
            {      
                if(value != null)
                {
                    super.data = value;
                    LbSequence.text=((this.owner as AdvancedDataGrid).dataProvider.getItemIndex(value)+1).toString();
                    
                }
            }    
        ]]>
    </mx:Script>
    
    <mx:Label  id="LbSequence" />
</mx:HBox> 
<mx:AdvancedDataGridColumn headerText=" "  itemRenderer=" cn.edu.whu.liesmars.renderer.SequenceItemRenderer"/>

-------------------------------------------------------------------------------------------------------------------------------------
 private function formatIndexNumber(item:Object, colum:Object):String
 {
     return indexNumLabelFun(item, colum.mx_internal::owner);
 }

 public static function indexNumLabelFun(value:Object, dataGrid:Object):String

 {
    var arr: Array = dataGrid.dataProvider.source;
    var indexNum: int = (arr.indexOf(value) + 1);            
    return indexNum.toString();
 }

<mx:DataGridColumn   headerText=" "  labelFunction="SimpleUtil.formatIndexNumber" width="50"/>

 ------------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" 
                    xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
    
    <fx:Script>
        <![CDATA[
            override public function set rowIndex(value:int):void
            {
                lblData.label = (value + 1).toString();
            }
        ]]>
    </fx:Script>
    
    <s:Button id="lblData" width="100%" height="100%"/>
    
</s:GridItemRenderer>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600"
               applicationComplete="applicationCompleteHandler(event)">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            private var ar:ArrayCollection;
            
            private function applicationCompleteHandler(event:FlexEvent):void
            {
                ar = new ArrayCollection();
                var user:User = null;
                for(var i:int = 1; i <= 100; i++) {
                    user = new User();
                    user.id = i;
                    user.username = "abc" + i;
                    user.password = "efg" + i;
                    ar.addItem(user);
                }
                this.dg.dataProvider = ar;
            }
        ]]>
    </fx:Script>
    <s:HGroup width="100%">
        <s:DataGrid id="dg" editable="true" rowHeight="25" width="100%" height="375" alternatingRowColors="[#FFFFFF,#EEEEEE]">  
            <s:columns>
                <s:ArrayList>
                    <s:GridColumn headerText=" " width="40" itemRenderer="CustomItemRenderer" editable="false"/>
                    <s:GridColumn dataField="id" headerText="ID"/>
                    <s:GridColumn dataField="username" headerText="USERNAME" />
                    <s:GridColumn dataField="password" headerText="PASSWORD"/>
                </s:ArrayList>
            </s:columns>
        </s:DataGrid>
    </s:HGroup>
</s:Application>

좋은 웹페이지 즐겨찾기