首页 > Flash开发技术分享 > Flex > FLEX 4.6 Spark组件介绍——DataGrid
2015
11-11

FLEX 4.6 Spark组件介绍——DataGrid

Datagrid是我们比较常用的一个控件,在FLEX3中的,我想网上的资料很多。到了4.5后换成Spart可能有些用法不用上了,在网上查了一些例子,整合在一起,当给自己作个笔记,也希望能对别人有个参考。

废话少说,直接上代码。

 

<?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:Declarations>
	<fx:Script>
		<![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; [Bindable] public static var initDG:ArrayCollection = new ArrayCollection([ {Artist:'01', Album:'Album 01', Year:'2008'}, {Artist:'01', Album:'Album 02', Year:'2009'}, {Artist:'03', Album:'Album 03', Year:'2007'}, {Artist:'03', Album:'Album 04', Year:'2003'}, ]); ]]>
		
	</fx:Script>
	
	
	<s:VGroup>
		<s:DataGrid id="myGrid" width="360" dataProvider="{initDG}">   
			<s:columns>
				<s:ArrayList>
					<s:GridColumn dataField="Artist" headerText="Artist"/>
					<s:GridColumn dataField="Album" headerText="Album"/>
					<s:GridColumn dataField="Year" headerText="Year" itemRenderer="CellRenderer"/>
				</s:ArrayList>
			</s:columns>       
		</s:DataGrid> 
	</s:VGroup>
</s:Application>
<?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 prepare(hasBeenRecycled:Boolean):void { lblData.text = data[column.dataField] if(this.data) { lblData.text = data[column.dataField]; if(this.data.Year >= 2008&&this.data.Artist==01)
						bgColor.color = 0xFF0000;
				//	bgColor.alpha=0;
					else
					bgColor.alpha=0;
				}
			}
		]]>
	</fx:Script>
	
	<s:Rect top="0" bottom="0" left="0" right="0">
		<s:fill>
			<s:SolidColor id="bgColor" color="0xFFFFFF"/>
			
		</s:fill>
	</s:Rect>
	<s:Label id="lblData" top="9" left="7" width="100%" height="100%" textAlign="center"/>
	
</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">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; // Data includes URL to album cover. [Bindable] private var initDG:ArrayCollection = new ArrayCollection([ {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99, Cover:'../assets/slanted.jpg', tabIndex:2}, {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99, Cover:'../assets/slanted.jpg', tabIndex:3}, {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99, Cover:'../assets/slanted.jpg', tabIndex:4}, {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99, Cover:'../assets/brighten.jpg', tabIndex:5} ]); ]]>
	</fx:Script>
	<s:layout>
		<s:VerticalLayout />
	</s:layout>
	
	<s:DataGrid id="myGrid" hasFocusableChildren="true" tabEnabled="true" tabChildren="true" focusEnabled="true" tabFocusEnabled="true" dataProvider="{initDG}" selectionMode="singleCell" tabIndex="1" variableRowHeight="true">   
		<s:columns>
			<s:ArrayList>
				<s:GridColumn dataField="Artist" rendererIsEditable="true">
					<s:itemRenderer>
						<fx:Component>
							<s:GridItemRenderer hasFocusableChildren="true" tabEnabled="true" tabChildren="true" focusEnabled="true" tabFocusEnabled="true" selectAll="meBtn.setFocus()">
								<fx:Script>
									<![CDATA[ import mx.controls.Alert; ]]>
								</fx:Script>
								<s:Button id="meBtn" label="{this.data.tabIndex} Click me" click="Alert.show('clicked','info')" tabIndex="{this.data.tabIndex}" tabEnabled="true" tabChildren="true" focusEnabled="true" tabFocusEnabled="true"/>
							</s:GridItemRenderer>
						</fx:Component>
					</s:itemRenderer>    
				</s:GridColumn>
				<s:GridColumn dataField="Album"/>
				<s:GridColumn dataField="Price"/>
			</s:ArrayList>
		</s:columns>       
	</s:DataGrid>
</s:Application>

<div class="dp-highlighter bg_java">
<div class="bar">
<div class="tools"><b></b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a>
<div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_5" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="0" height="0" name="ZeroClipboardMovie_5" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&width=0&height=0" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j">
<li class="alt"><span><span><?xml&nbsp;version=</span><span class="string">"1.0"</span><span>&nbsp;encoding=</span><span class="string">"utf-8"</span><span>?>&nbsp;&nbsp;</span></span></li>
<li class=""><span><s:Application&nbsp;xmlns:fx=<span class="string">"http://ns.adobe.com/mxml/2009"</span><span>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:s=<span class="string">"library://ns.adobe.com/flex/spark"</span><span>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:mx=<span class="string">"library://ns.adobe.com/flex/mx"</span><span>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:components=<span class="string">"com.fusioncharts.components.*"</span><span>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minWidth=<span class="string">"955"</span><span>&nbsp;minHeight=</span><span class="string">"600"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<fx:Style&nbsp;source=<span class="string">"create.css"</span><span>/>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<fx:Script>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<![CDATA[&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">import</span><span>&nbsp;spark.events.GridEvent;&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;function&nbsp;onGridDoubleClick(&nbsp;e:GridEvent&nbsp;):</span><span class="keyword">void</span><span>&nbsp;{&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gridSelectionLabel.text&nbsp;=&nbsp;<span class="string">"double-click:&nbsp;"</span><span>&nbsp;+&nbsp;TweetersList.getItemAt(&nbsp;e.rowIndex&nbsp;)[&nbsp;e.column.dataField&nbsp;]&nbsp;as&nbsp;String;&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;function&nbsp;onGridClick(&nbsp;e:GridEvent&nbsp;):</span><span class="keyword">void</span><span>&nbsp;{&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gridSelectionLabel.text&nbsp;=&nbsp;<span class="string">"click:&nbsp;"</span><span>&nbsp;+&nbsp;TweetersList.getItemAt(&nbsp;e.rowIndex&nbsp;)[&nbsp;e.column.dataField&nbsp;]&nbsp;as&nbsp;String;&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]]>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</fx:Script>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<fx:Declarations>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--&nbsp;将非可视元素(例如服务、值对象)放在此处&nbsp;-->&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;</fx:Declarations>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<s:TitleWindow&nbsp;x=<span class="string">"10"</span><span>&nbsp;y=</span><span class="string">"10"</span><span>&nbsp;width=</span><span class="string">"391"</span><span>&nbsp;height=</span><span class="string">"463"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:DataGrid&nbsp;&nbsp;&nbsp;x=<span class="string">"71"</span><span>&nbsp;y=</span><span class="string">"89"</span><span>&nbsp;width=</span><span class="string">"274"</span><span>&nbsp;height=</span><span class="string">"210"</span><span>&nbsp;requestedRowCount=</span><span class="string">"4"</span><span>&nbsp;gridDoubleClick=</span><span class="string">"onGridDoubleClick(&nbsp;event&nbsp;);"</span><span>&nbsp;doubleClickEnabled=</span><span class="string">"true"</span><span>&nbsp;gridClick=</span><span class="string">"onGridClick(&nbsp;event&nbsp;);"</span><span>&nbsp;alternatingRowColors=</span><span class="string">"[&nbsp;#eeeeFF,&nbsp;#eeFFee,&nbsp;#FFeeee&nbsp;]"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:columns>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:ArrayList>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:GridColumn&nbsp;dataField=<span class="string">"dataField1"</span><span>&nbsp;headerText=</span><span class="string">"列&nbsp;1"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:GridColumn>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:GridColumn&nbsp;dataField=<span class="string">"dataField2"</span><span>&nbsp;headerText=</span><span class="string">"列&nbsp;2"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:itemRenderer>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fx:Component>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:DefaultGridItemRenderer&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fontSize=<span class="string">"24"</span><span>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=<span class="string">"{data.dataField4}"</span><span>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fontWeight=<span class="string">"bold"</span><span>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textAlign=<span class="string">"center"</span><span>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fontFamily=<span class="string">"Courier&nbsp;New"</span><span>&nbsp;/>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</fx:Component>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:itemRenderer>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:GridColumn>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:GridColumn&nbsp;&nbsp;dataField=<span class="string">"dataField3"</span><span>&nbsp;headerText=</span><span class="string">"列&nbsp;3"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:itemRenderer>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:Image&nbsp;source=<span class="string">"{data.dataField3}"</span><span>/>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<mx:LinkButton&nbsp;toolTip=<span class="string">"清除"</span><span>&nbsp;label=</span><span class="string">"清除"</span><span>&nbsp;&nbsp;textDecoration=</span><span class="string">"underline"</span><span>&nbsp;color=</span><span class="string">"#2066CF"</span><span>&nbsp;fontWeight=</span><span class="string">"normal"</span><span>/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<mx:LinkButton&nbsp;toolTip=<span class="string">"确认"</span><span>&nbsp;label=</span><span class="string">"确认"</span><span>&nbsp;&nbsp;textDecoration=</span><span class="string">"underline"</span><span>&nbsp;color=</span><span class="string">"#2066CF"</span><span>&nbsp;fontWeight=</span><span class="string">"normal"</span><span>/>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:GridItemRenderer>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</fx:Component>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:itemRenderer>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:GridColumn>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:ArrayList>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:columns>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:typicalItem>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fx:Object&nbsp;dataField1=<span class="string">"示例数据"</span><span>&nbsp;dataField2=</span><span class="string">"示例数据"</span><span>&nbsp;dataField3=</span><span class="string">"示例数据"</span><span>></fx:Object>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:typicalItem>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:ArrayList&nbsp;id=<span class="string">"TweetersList"</span><span>>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fx:Object&nbsp;dataField1=<span class="string">"数据1"</span><span>&nbsp;dataField2=</span><span class="string">"数据1"</span><span>&nbsp;dataField3=</span><span class="string">"03.gif"</span><span>&nbsp;dataField4=</span><span class="string">"#f906c6"</span><span>></fx:Object>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fx:Object&nbsp;dataField1=<span class="string">"数据2"</span><span>&nbsp;dataField2=</span><span class="string">"数据2"</span><span>&nbsp;dataField3=</span><span class="string">"03.gif"</span><span>&nbsp;dataField4=</span><span class="string">"#f9f606"</span><span>></fx:Object>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fx:Object&nbsp;dataField1=<span class="string">"数据3"</span><span>&nbsp;dataField2=</span><span class="string">"数据3"</span><span>&nbsp;dataField3=</span><span class="string">"04.gif"</span><span>&nbsp;dataField4=</span><span class="string">"#f9acf6"</span><span>></fx:Object>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fx:Object&nbsp;dataField1=<span class="string">"数据4"</span><span>&nbsp;dataField2=</span><span class="string">"数据4"</span><span>&nbsp;dataField3=</span><span class="string">"03.gif"</span><span>&nbsp;dataField4=</span><span class="string">"#f9f6b6"</span><span>></fx:Object>&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:ArrayList>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s:DataGrid>&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:Label&nbsp;id=<span class="string">"gridSelectionLabel"</span><span>&nbsp;x=</span><span class="string">"71"</span><span>&nbsp;y=</span><span class="string">"344"</span><span>&nbsp;width=</span><span class="string">"187"</span><span>&nbsp;height=</span><span class="string">"31"</span><span>&nbsp;text=</span><span class="string">"标签"</span><span>/>&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
<li class=""><span>&nbsp;&nbsp;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</s:TitleWindow>&nbsp;&nbsp;</span></li>
<li class=""><span></s:Application>&nbsp;&nbsp;</span></li>
</ol>
</div>
<pre name="code" class="java" style="display: none;"><?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" xmlns:components="com.fusioncharts.components.*" minWidth="955" minHeight="600">
	<fx:Style source="create.css"/>
	<fx:Script>
		<![CDATA[ import spark.events.GridEvent; private function onGridDoubleClick( e:GridEvent ):void { gridSelectionLabel.text = "double-click: " + TweetersList.getItemAt( e.rowIndex )[ e.column.dataField ] as String; } private function onGridClick( e:GridEvent ):void { gridSelectionLabel.text = "click: " + TweetersList.getItemAt( e.rowIndex )[ e.column.dataField ] as String; } ]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:TitleWindow x="10" y="10" width="391" height="463">
		<s:DataGrid x="71" y="89" width="274" height="210" requestedRowCount="4" gridDoubleClick="onGridDoubleClick( event );" doubleClickEnabled="true" gridClick="onGridClick( event );" alternatingRowColors="[ #eeeeFF, #eeFFee, #FFeeee ]">
			<s:columns>
				<s:ArrayList>
					<s:GridColumn dataField="dataField1" headerText="列 1">
					
					</s:GridColumn>
					<s:GridColumn dataField="dataField2" headerText="列 2">
						<s:itemRenderer>
							<fx:Component>
								<s:DefaultGridItemRenderer fontSize="24" color="{data.dataField4}" fontWeight="bold" textAlign="center" fontFamily="Courier New" />
							</fx:Component>
						</s:itemRenderer>
					</s:GridColumn>
					<s:GridColumn dataField="dataField3" headerText="列 3">
						<s:itemRenderer>
							<fx:Component>
								<s:GridItemRenderer >
									
									<s:HGroup> 
										<s:Image source="{data.dataField3}"/>
										<mx:LinkButton toolTip="清除" label="清除" textDecoration="underline" color="#2066CF" fontWeight="normal"/>   
										<mx:LinkButton toolTip="确认" label="确认" textDecoration="underline" color="#2066CF" fontWeight="normal"/>
										
									</s:HGroup>  
									
									
						
								</s:GridItemRenderer>
							</fx:Component>
						</s:itemRenderer>
					</s:GridColumn>
				</s:ArrayList>
			</s:columns>
			<s:typicalItem>
				<fx:Object dataField1="示例数据" dataField2="示例数据" dataField3="示例数据"></fx:Object>
			</s:typicalItem>
			<s:ArrayList id="TweetersList">
				<fx:Object dataField1="数据1" dataField2="数据1" dataField3="03.gif" dataField4="#f906c6"></fx:Object>
				<fx:Object dataField1="数据2" dataField2="数据2" dataField3="03.gif" dataField4="#f9f606"></fx:Object>
				<fx:Object dataField1="数据3" dataField2="数据3" dataField3="04.gif" dataField4="#f9acf6"></fx:Object>
				<fx:Object dataField1="数据4" dataField2="数据4" dataField3="03.gif" dataField4="#f9f6b6"></fx:Object>
			</s:ArrayList>
		</s:DataGrid>
		<s:Label id="gridSelectionLabel" x="71" y="344" width="187" height="31" text="标签"/>
	

	</s:TitleWindow>
</s:Application>
</pre>



<pre></pre>




<pre></pre>
<div style="padding-top:20px">

版权声明:本文为博主原创文章,未经博主允许不得转载。
</div>

最后编辑:
作者:细水长流
关注互联网+ 关注o2o 关注创业创新领域

留下一个回复