Flex

Flex2でDataGridに動的カラム作成

<!-- hoge.mxml -->
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="initColumns()">
  <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10" lockedColumnCount="1"></mx:DataGrid>
  <mx:Script source="hoge.as" />
</mx:Application>
// hoge.as
 
private function initColumns() : void {
  var cols:Array = this.gridManHour.columns;
  cols.length = 0;   // 既存カラムを削除
 
  var col:DataGridColumn = new DataGridColumn();
  col.headerText ="ほげ";
  col.dataField = "hoge"
  cols.push(col)
 
  col = new DataGridColumn();
  col.headerText ="ふが";
  col.dataField = "fuga"
  cols.push(col)
 
  // 再代入しないとダメらしい
  this.gridManHour.columns = cols;
 
  // dataProviderは最後に定義する
  this.gridManHour.dataProvider = [{"hoge": "a", "fuga": "b"},{"hoge": "c", "fuga": "d"}];
};
 
 
flex.txt · 最終更新: 2007/10/03 16:51 (外部編集)
 
特に明示されていない限り、本Wikiの内容は次のライセンスに従います: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki