2012-02-27 118 views
1

行數&表格的列是從用戶獲取的,以便在一個標題窗口中創建表格。 進入我打開一個窗口組成的表(AdvancedDatagrid)後會發生什麼是如果生成的表超過窗口寬度和高度,表出來的窗口。 如何保留TitleWindow中的表格。使用AdvancedDatagrid動態創建表格

<?xml version="1.0" encoding="utf-8"?> 
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" 
     title="Table Details" 
     initialize="tableDetailsWindow_initializeHandler(event)" 
     chromeColor="#5C809B" color="#D8E0E5" 
     creationComplete="tableDetailsWindow_creationCompleteHandler(event)" 
     width="506"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 
      import mx.controls.Alert; 
      import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn; 
      import mx.core.FlexGlobals; 
      import mx.events.CloseEvent; 
      import mx.events.FlexEvent; 
      import mx.managers.PopUpManager; 

      import spark.components.TextInput; 
      import spark.components.TileGroup; 

      [Bindable] 
      public var columnNameGroup :TileGroup; 

      [Bindable] 
      public var columnCount:Number; 

      [Bindable] 
      public var rowCount:Number; 

      var rowCollection : ArrayCollection = new ArrayCollection(); 
      var columnNames :ArrayCollection = new ArrayCollection(); 

         protected function tableDetailsWindow_initializeHandler(event:FlexEvent):void 
      { 
       dataGrid.rowCount= Number(FlexGlobals.topLevelApplication.insertTableConfigWindow.rowCount.text)+1; 
      } 


      protected function tableDetailsWindow_creationCompleteHandler(event:FlexEvent):void 
      { 
       columnNameGroup = FlexGlobals.topLevelApplication.insertTableConfigWindow.tileGroupOfColsInfo; 
       columnCount = Number(FlexGlobals.topLevelApplication.insertTableConfigWindow.columnCount.text); 
       rowCount = Number(FlexGlobals.topLevelApplication.insertTableConfigWindow.rowCount.text); 

           //Creation of Column Name collection 
       for(var i:Number= 0; i< columnCount; i++){ 
        var textInputId :String ="textInput"+ (i+1); 
        var textInput :TextInput = columnNameGroup.getChildByName(textInputId) as TextInput; 
        columnNames.addItem(textInput.text); 
       } 

           //Creation of Rows collection 
       for(var j:Number= 0; j< rowCount; j++){ 
        var obj:Object = new Object(); 
        for each(var colName : * in columnNames){ 
         obj.colName =""; 
        } 
        rowCollection.addItem(obj); 
       } 

       dataGrid.dataProvider = rowCollection; 

       var columns:Array = dataGrid.columns; 

       for(var k:Number= 0; k< columnNames.length; k++){ 

        var adgColumn:AdvancedDataGridColumn = new AdvancedDataGridColumn(); 
        adgColumn.dataField = columnNames.getItemAt(k) as String; 
        adgColumn.editable = true; 

        columns.push(adgColumn); 
       } 
       dataGrid.columns = columns; 
      } 


     ]]> 
    </fx:Script> 

    <mx:AdvancedDataGrid id="dataGrid" 
    editable="true" verticalScrollPolicy="off" 
    sortableColumns="false" 
    x="0" y="0" /> 



</s:TitleWindow> 
+0

你可以發佈'titleWindow'代碼嗎? – randomUser56789 2012-02-27 08:03:30

回答

0

你試過設置AdvancedDataGrid的寬度嗎?

<mx:AdvancedDataGrid id="dataGrid" 
    width="506" <=== Set the width here 
    editable="true" verticalScrollPolicy="off" 
    sortableColumns="false" 
    x="0" y="0" /> 

或者,您可以動態地設置寬度,但是,那麼你需要聽resize事件的窗口。