Flexノート_MXデータGrid、リスト、ツリー
16077 ワード
ListBaseとAdvancedListBase
lockedColumnCount、lockedRowCount、rowCount、rowHeight、selectable、selectedIndex、
selectedIndices、selectedItem、selectedItems、variableRowHeight、wordWrap
データ・ソース、コレクションとdataProvider
DataProviderを入力:
コレクションのタイプ:
集合の使用者:
AdvancedDataGrid、ButtonBar、Charting components including、Legends、ColorPicker、ComboBox、Menu、MenuBar、OLAPDataGrid、PopUpMenuButton、Repeater、TabBar、DataGrid、DateField、
HorizontalList、LinkBar、List、TileList、ToggleButtonBar、Tree
コレクションの初期化
<s:ArrayCollection id="myAC">
<fx:Object label="item1" data="data1"/>
<fx:Object label="item2" data="data2"/>
<fx:Object label="item3" data="data3"/>
</s:ArrayCollection>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
public var myAc:ArrayCollection = new ArrayCollection([
{ label:"item1", data:"data1"},
{ label:"item2", data:"data2"},
{ label:"item3", data:"data3"}
]);
]]>
</fx:Script>
集合の塗りつぶし
Listコンポーネント:
<?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">
<mx:List id="myFriends" x="10" y="10">
<fx:String>friend 1</fx:String>
<fx:String>friend 2</fx:String>
<fx:String>friend 3</fx:String>
</mx:List>
</s:Application>
<?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">
<fx:Declarations>
<s:ArrayCollection id="myAC">
<fx:Object label="friend 1"/>
<fx:Object label="friend 2"/>
<fx:Object label="friend 3"/>
</s:ArrayCollection>
</fx:Declarations>
<mx:List id="myFriends" x="10" y="10" dataProvider="{myAC}">
</mx:List>
</s:Application>
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{label:"friend 1"},
{label:"friend 2"},
{label:"friend 3"}
]);
]]>
</fx:Script>
<mx:List id="myFriends" x="10" y="10" dataProvider="{myAC}">
</mx:List>
</s:Application>
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"friend 1"},
{name:"friend 2"},
{name:"friend 3"}
]);
]]>
</fx:Script>
<mx:List id="myFriends" x="10" y="10" dataProvider="{myAC}" labelField="name">
</mx:List>
</s:Application>
HorizontalListコンポーネント
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"friend 1"},
{name:"friend 2"},
{name:"friend 3"}
]);
]]>
</fx:Script>
<mx:HorizontalList id="myFriends" x="10" y="10" dataProvider="{myAC}" labelField="name"/>
</s:Application>
TileListコンポーネント
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"friend 1"},
{name:"friend 2"},
{name:"friend 3"},
{name:"friend 4"},
{name:"friend 5"},
{name:"friend 6"},
{name:"friend 7"},
{name:"friend 8"}
]);
]]>
</fx:Script>
<mx:TileList id="myFriends" x="10" y="10" dataProvider="{myAC}" labelField="name"
direction="vertical"/>
</s:Application>
DataGridコンポーネント
<?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">
<mx:DataGrid id="dg" width="500" height="200">
<mx:dataProvider>
<fx:Object name="item1" email="[email protected]"/>
<fx:Object name="item2" email="[email protected]"/>
<fx:Object name="item3" email="[email protected]"/>
</mx:dataProvider>
</mx:DataGrid>
</s:Application>
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"item1", email:"[email protected]", url:"www.url1.com"},
{name:"item2", email:"[email protected]", url:"www.url2.com"},
{name:"item3", email:"[email protected]", url:"www.url3.com"},
]);
]]>
</fx:Script>
<mx:DataGrid id="dg" width="500" height="150" dataProvider="{myAC}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Contact Name" width="300" />
<mx:DataGridColumn dataField="email" headerText="E-Mail" width="200" />
<mx:DataGridColumn dataField="url" headerText="Web Site" width="200" />
</mx:columns>
</mx:DataGrid>
</s:Application>
sortable、sortCompareFunction、sortDescending(true:降順、false:昇順)、
Visible、width、wordWrap(DataGridコンポーネントのvariableRowHeightプロパティがtrueに設定されていることを確認する)
Treeコンポーネント
<?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">
<fx:Declarations>
<fx:XMLList id="myXML">
<friends>
<friend name="Item1"/>
<friend name="Item2"/>
<friend name="Item2"/>
</friends>
</fx:XMLList>
</fx:Declarations>
</s:Application>
<mx:XMLList source="my.xml" id="myXML"/>
<?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">
<fx:Declarations>
<mx:XMLListCollection id="myXMLCollection">
<fx:XMLList id="myXML" xmlns="">
<friends label="Friends">
<friend label="Friend"/>
</friends>
<families label="Families">
<family label="Family"/>
</families>
</fx:XMLList>
</mx:XMLListCollection>
</fx:Declarations>
</s:Application>
<?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">
<fx:Declarations>
<mx:XMLListCollection id="myXMLCollection">
<fx:XMLList id="myXML" xmlns="">
<friends label="Friends">
<friend label="Friend1"/>
<friend label="Friend2"/>
<friend label="Friend3"/>
</friends>
<families label="Families">
<family label="Family1"/>
<family label="Family2"/>
</families>
</fx:XMLList>
</mx:XMLListCollection>
</fx:Declarations>
<mx:Tree dataProvider="{myXMLCollection}"
labelField="@label"
width="300" height="200"/>
</s:Application>
ListベースMXコンポーネントとのインタラクション
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
import mx.controls.Alert;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"item1",email:"[email protected]"},
{name:"item2",email:"[email protected]"}
]);
public function contactDataGrid_clickHandler(event:ListEvent):void {
Alert.show("You have clicked on row " + event.rowIndex + " and col "
+ event.columnIndex + "." + "Witch is for " +
event.currentTarget.selectedItem.name);
}
]]>
</fx:Script>
<mx:DataGrid id="contactDataGrid" width="500" height="150"
dataProvider="{myAC}"
itemClick="contactDataGrid_clickHandler( event )">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Contact Name" width="300"/>
<mx:DataGridColumn dataField="email" headerText="E-mail" width="200"/>
</mx:columns>
</mx:DataGrid>
</s:Application>
...
public function contactDataGrid_clickHandler():void {
Alert.show("Name : "+ contactDataGrid.selectedItem.name);
}
xmlns:mx="library://ns.adobe.com/flex/mx"minWidth="955"minHeight="600">
import mx.collections.ArrayCollection;
import mx.events.ListEvent;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"item1",email:"[email protected]"},
{name:"item2",email:"[email protected]"}
]);
]]>