<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Li Guoliang &#187; DataGridColumn</title>
	<atom:link href="http://liguoliang.com/tag/datagridcolumn/feed/" rel="self" type="application/rss+xml" />
	<link>http://liguoliang.com</link>
	<description>ActionScript Flex Java JEE PHP...</description>
	<lastBuildDate>Mon, 21 May 2012 17:04:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>DragDrop时, 使用DragEvent.dragInitiator来获得Drag源头, 而非DragEvent.relatedObject</title>
		<link>http://liguoliang.com/2010/dragdrop%e6%97%b6-%e4%bd%bf%e7%94%a8dragevent-draginitiator%e6%9d%a5%e8%8e%b7%e5%be%97drag%e6%ba%90%e5%a4%b4-%e8%80%8c%e9%9d%9edragevent-relatedobject/</link>
		<comments>http://liguoliang.com/2010/dragdrop%e6%97%b6-%e4%bd%bf%e7%94%a8dragevent-draginitiator%e6%9d%a5%e8%8e%b7%e5%be%97drag%e6%ba%90%e5%a4%b4-%e8%80%8c%e9%9d%9edragevent-relatedobject/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 09:23:19 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DataGridColumn]]></category>
		<category><![CDATA[Drag]]></category>
		<category><![CDATA[Drag and Drop]]></category>
		<category><![CDATA[DragEvent]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2010/01/1115/</guid>
		<description><![CDATA[首发: <a title="http://riashanghai.com/node/123" href="http://riashanghai.com/node/123">http://riashanghai.com/node/123</a>
<strong>问题描述: </strong>
在进行DragDrop时, 我使用了DragDrop.relatedObject来获得Drag触发的UIComponent 
如: var dargUI:TileList = e.relatedObject as <p class='read-more'><a href='http://liguoliang.com/2010/dragdrop%e6%97%b6-%e4%bd%bf%e7%94%a8dragevent-draginitiator%e6%9d%a5%e8%8e%b7%e5%be%97drag%e6%ba%90%e5%a4%b4-%e8%80%8c%e9%9d%9edragevent-relatedobject/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>首发: <a title="http://riashanghai.com/node/123" href="http://riashanghai.com/node/123">http://riashanghai.com/node/123</a></strong></p>
<p><strong>问题描述: </strong></p>
<p>在进行DragDrop时, 我使用了DragDrop.relatedObject来获得Drag触发的UIComponent </p>
<p>如: var dargUI:TileList = e.relatedObject as TileList;</p>
<p>在AIR中运行, 可用且没有任何错误, 但当使用浏览器版本时, e.relatedObject为null, 上一行代码报错. </p>
<p>&#160;</p>
<p><strong>解决方法</strong>:</p>
<p>因此, 如果需要在两种环境中都可以运行, 应使用e.dragInitiator来获取Drag触发的源头:</p>
<pre class="java" name="code">	//----------------------------------
	//  dragInitiator 来源: DragEvent
	//----------------------------------

	/**
	 *  The component that initiated the drag.
	 */
	public var dragInitiator:IUIComponent;</pre>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2010/dragdrop%e6%97%b6-%e4%bd%bf%e7%94%a8dragevent-draginitiator%e6%9d%a5%e8%8e%b7%e5%be%97drag%e6%ba%90%e5%a4%b4-%e8%80%8c%e9%9d%9edragevent-relatedobject/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用ActionScript建立DataGrid, 添加右键, 增加列, 并设定列的ItemRenderer</title>
		<link>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8actionscript%e5%bb%ba%e7%ab%8bdatagrid-%e6%b7%bb%e5%8a%a0%e5%8f%b3%e9%94%ae-%e5%a2%9e%e5%8a%a0%e5%88%97-%e5%b9%b6%e8%ae%be%e5%ae%9a%e5%88%97%e7%9a%84itemrender/</link>
		<comments>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8actionscript%e5%bb%ba%e7%ab%8bdatagrid-%e6%b7%bb%e5%8a%a0%e5%8f%b3%e9%94%ae-%e5%a2%9e%e5%8a%a0%e5%88%97-%e5%b9%b6%e8%ae%be%e5%ae%9a%e5%88%97%e7%9a%84itemrender/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 16:59:39 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Air右键]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[DataGridColumn]]></category>
		<category><![CDATA[Flex右键]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2009/01/679/</guid>
		<description><![CDATA[很多时候为了获得对组件的灵活控制, 不得不放弃MXML, 直接使用ActionScript.<p class='read-more'><a href='http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8actionscript%e5%bb%ba%e7%ab%8bdatagrid-%e6%b7%bb%e5%8a%a0%e5%8f%b3%e9%94%ae-%e5%a2%9e%e5%8a%a0%e5%88%97-%e5%b9%b6%e8%ae%be%e5%ae%9a%e5%88%97%e7%9a%84itemrender/'></a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>很多时候为了获得对组件的灵活控制, 不得不放弃MXML, 直接使用ActionScript.
<pre class="java" name="code">
//新建一个DataGrid _dataGrid = new DataGrid();
//增加右键
var menu:NativeMenu = new NativeMenu();
var menuItemDelete:NativeMenuItem = new NativeMenuItem(&quot;Delete&quot;);
//监听事件,在右键选定Delete时运行该函数
 menuItemDelete.addEventListener(Event.SELECT, onMenuDeleteClicked);
//将该menuItem加入到Menu中
menu.addItem(menuItemDelete);
 _dataGrid.contextMenu = menu; //将菜单加入到DataGrid中 

columnLocale = new DataGridColumn(); //新建一个列
columnLocale.dataField ="locale";//设定DataGrid中locale列的EditItem;
comboBoxLocaleEditor = new ClassFactory(ComboBox); // D
comboBoxLocaleEditor.properties = {dataProvider : LocalizationItem.localeArray} //设定该EditorItem的属性
columnLocale.itemEditor = comboBoxLocaleEditor; 

var columnGender:DataGridColumn = new DataGridColumn();
 columnGender.headerText = "Gender&#038;quot";
columnGender.dataField = "Gender_";
//使用ItemRender
columnGender.itemRenderer = new ClassFactory(Gender_Label);
 _dataGrid.showHeaders = false; //隐藏DataGrid的Header
_dataGrid.columns = [columnLocale, columnGender]; //这一个数组,存放DataGrid的Column 

_dataGrid.dataProvider = value; //设定dataProvider </pre>
<p>具体在实际中的使用, 无异于MXML. </p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8actionscript%e5%bb%ba%e7%ab%8bdatagrid-%e6%b7%bb%e5%8a%a0%e5%8f%b3%e9%94%ae-%e5%a2%9e%e5%8a%a0%e5%88%97-%e5%b9%b6%e8%ae%be%e5%ae%9a%e5%88%97%e7%9a%84itemrender/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>使用ItemRenderer处理基于List容器的显示内容 [DataGrid, Tree, List等]</title>
		<link>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8itemrender%e5%a4%84%e7%90%86%e5%9f%ba%e4%ba%8elist%e5%ae%b9%e5%99%a8%e7%9a%84%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9-datagrid-tree-list%e7%ad%89/</link>
		<comments>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8itemrender%e5%a4%84%e7%90%86%e5%9f%ba%e4%ba%8elist%e5%ae%b9%e5%99%a8%e7%9a%84%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9-datagrid-tree-list%e7%ad%89/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 16:52:06 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[DataGridColumn]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2009/01/678/</guid>
		<description><![CDATA[如Student中有一Gender_属性, 1表示男生, 2表示女生, 3表示未知, 现在有下要求: 1. 在DataGrid中不可以显示1, 2,3, 应显示 男女 [ 该功能可由LabelFunction实现], 2. 如果为男生,, 则”男生”颜色为红色, 女生颜色为默认, 未知字体大小为10号<p class='read-more'><a href='http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8itemrender%e5%a4%84%e7%90%86%e5%9f%ba%e4%ba%8elist%e5%ae%b9%e5%99%a8%e7%9a%84%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9-datagrid-tree-list%e7%ad%89/'></a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p><strong>具体的情况</strong>如:<a href="http://liguoliang.com/2009/01/668/">使用labelFunction处理DataGrid显示内容 </a>, 只是这里使用的是ItemRender来实现并实现更多功能.</p>
<p>如Student中有一Gender_属性, 1表示男生, 2表示女生, 3表示未知, 现在有下要求:</p>
<p>1. 在DataGrid中不可以显示1, 2,3, 应显示 男女 [ 该功能可由LabelFunction实现],</p>
<p>2. 如果为男生,, 则”男生”颜色为红色, 女生颜色为默认, 未知字体大小为10号</p>
<p><strong>具体实现:</strong></p>
<pre class="java" name="code">			var columnGender:DataGridColumn = new DataGridColumn();
			columnGender.headerText = &quot;Gender&quot;;
			columnGender.dataField = &quot;Gender_&quot;; //使用ItemRender
			columnGender.itemRenderer =  new ClassFactory(Gender_Label);
			//columnGender.labelFunction = formatGender;

			_dataGridStudent.columns = [columnID, columnName, columnAge, columnGender];</pre>
<p>ItemRender实现: 该类将继承List, 重写其UpdateDisplayList函数, 如下: </p>
<pre class="java" name="code">package com.test.itemRender
{
import mx.controls.Label;
import mx.controls.listClasses.ListBase;

public class Gender_Label extends Label
{
	/**
	 * 构造函数
	 */
	public function Gender_Label() {
		super();
	}

	override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
		super.updateDisplayList(unscaledWidth, unscaledHeight);
		if(data.Gender_ == 1) {
             setStyle('fontSize',14);
             setStyle('fontWeight', 'bold');
             setStyle('color', 0xDD0000);
             this.text = &quot;男生&quot;;
		 }else if(data.Gender_ == 2) {
		 	setStyle('fontSize',14);
		 	this.text = &quot;女生&quot;
		 }
		 //otherwise, return the label to its regular state
		 else {
		     setStyle('fontSize', 10);
             this.text = &quot;未知&quot;;
		 }
	}

}// end of class
}// end of package</pre>
<p><strong>最终效果:</strong> </p>
<p><a href="http://liguoliang.com/wp-content/uploads/2009/01/image3.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="282" alt="image" src="http://liguoliang.com/wp-content/uploads/2009/01/image-thumb3.png" width="344" border="0" /></a></p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8itemrender%e5%a4%84%e7%90%86%e5%9f%ba%e4%ba%8elist%e5%ae%b9%e5%99%a8%e7%9a%84%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9-datagrid-tree-list%e7%ad%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用labelFunction处理DataGrid显示内容</title>
		<link>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8labelfunction%e5%a4%84%e7%90%86datagrid%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9/</link>
		<comments>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8labelfunction%e5%a4%84%e7%90%86datagrid%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 09:31:44 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[DataGridColumn]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2009/01/668/</guid>
		<description><![CDATA[在设定了DataGrid的DataProvider, 设定DataGridColumn及其相应的DataField之后, DataGrid就可正常显示, 但有时候需要稍微处理一下显示内容: 如 某ArrayCollection中含有一组Student, Student对象具有gender属性, 其中1代表男, 2代表女, 3代表不确定. 此时需要使用labelFunction进行处理显示内容.<p class='read-more'><a href='http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8labelfunction%e5%a4%84%e7%90%86datagrid%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9/'></a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>在设定了DataGrid的DataProvider, 设定DataGridColumn及其相应的DataField之后, DataGrid就可正常显示, 但有时候需要稍微处理一下显示内容: 如 某ArrayCollection中含有一组Student, Student对象具有gender属性, 其中1代表男, 2代表女, 3代表不确定. 此时需要使用labelFunction进行处理显示内容.</p>
<p><a href="http://liguoliang.com/wp-content/uploads/2009/01/image.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" src="http://liguoliang.com/wp-content/uploads/2009/01/image-thumb.png" border="0" alt="image" width="445" height="344" /></a> <a href="http://liguoliang.com/wp-content/uploads/2009/01/image1.png"><img style="border: 0pt none; display: inline;" title="image" src="http://liguoliang.com/wp-content/uploads/2009/01/image1.png" border="0" alt="image" width="437" height="344" /></a></p>
<p><strong>原理:</strong></p>
<p>DataGrid通过DataGridColum函数中的itemToLabel实现数据源到现实内容的过程,</p>
<p>当DataGrid 某列的labelFunction不为空时, DataGridColumn的itemToLabel函数将执行:</p>
<p>if (labelFunction != null)<br />
return labelFunction(data, this);</p>
<p>具体可参见类DataGridColumn的itemToLabel函数.</p>
<p><strong>使用方法:</strong></p>
<pre class="java">var columnGender:DataGridColumn = new DataGridColumn();  //增加一个Column
			columnGender.headerText = "Gender";
			columnGender.dataField = "Gender_";
			columnGender.labelFunction = formatGender;  //设定LabelFunction

			_dataGridStudent.columns = [columnID, columnName, columnAge, columnGender];  //将Column加入到DG中.总共四个Column</pre>
<p>labelFunction函数</p>
<pre class="java">	/** 设定DataGrid 性别栏显示内容*/
	 private function formatGender(item:Object, c:DataGridColumn):String {
	 	var gender:String;
	 	if(item.Gender_ == 1) {
	 		gender = "男";
	 	}else if(item.Gender_ == 2) {
	 		gender = "女";
	 	}else {
	 		gender = "未知";
	 	}
	 	return gender;
	 }</pre>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2009/%e4%bd%bf%e7%94%a8labelfunction%e5%a4%84%e7%90%86datagrid%e6%98%be%e7%a4%ba%e5%86%85%e5%ae%b9/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flex中获得DataGrid中编辑前后的数据</title>
		<link>http://liguoliang.com/2008/flex%e4%b8%ad%e8%8e%b7%e5%be%97datagrid%e4%b8%ad%e7%bc%96%e8%be%91%e5%89%8d%e5%90%8e%e7%9a%84%e6%95%b0%e6%8d%ae/</link>
		<comments>http://liguoliang.com/2008/flex%e4%b8%ad%e8%8e%b7%e5%be%97datagrid%e4%b8%ad%e7%bc%96%e8%be%91%e5%89%8d%e5%90%8e%e7%9a%84%e6%95%b0%e6%8d%ae/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 03:28:21 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[DataGridColumn]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2008/10/256/</guid>
		<description><![CDATA[问题:
在使用DataGrid进行数据编辑时, 我们不可避免的需要对数据的输入进行检验, 修正等错误.
解决方法:
监听DataGrid的editEnd事件:DataGridEvent.ITEM_EDIT_END.改事件中包含有正在编辑的DataGridColumn[列名], 编辑前的数据, 编辑结<p class='read-more'><a href='http://liguoliang.com/2008/flex%e4%b8%ad%e8%8e%b7%e5%be%97datagrid%e4%b8%ad%e7%bc%96%e8%be%91%e5%89%8d%e5%90%8e%e7%9a%84%e6%95%b0%e6%8d%ae/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<h3>问题:</h3>
<p>在使用DataGrid进行数据编辑时, 我们不可避免的需要对数据的输入进行检验, 修正等错误.</p>
<h3>解决方法:</h3>
<p>监听DataGrid的editEnd事件:DataGridEvent.ITEM_EDIT_END.改事件中包含有正在编辑的DataGridColumn[列名], 编辑前的数据, 编辑结束后的数据, 等等</p>
<h3>具体实现:</h3>
<p>1. 获得当前编辑的DataGridColumn;  2. 获得编辑前后的数据;</p>
<pre class="java" name="code">	/**
	 * 响应EditEnd
	 * 获得当前编辑的DataGridColumn; 2. 获得编辑前后的数据;
	 */
	 private function onEditEnd(e:DataGridEvent):void {
	 	var beingEditField:String = e.dataField;  //获得当前列的dataField
	 	if(beingEditField == "locale") {
		 	var oldLocal:String = e.itemRenderer.data.locale;
			var newLocale:String = _dataGrid.itemEditorInstance[columnLocale.editorDataField]; //hashMap Key is String
			Alert.show("您正在编辑列: " + beingEditField + " 将: " + oldLocal + " 编辑为: " + newLocale); //在此处可以加入需要的数据验证,或是自动修正等等功能.可以使用	e.preventDefault()来阻止默认行为
			}
	 	}......
	 }</pre>
<h3>抓图:</h3>
<p><a href="http://liguoliang.com/wp-content/uploads/2008/10/image15.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" src="http://liguoliang.com/wp-content/uploads/2008/10/image-thumb15.png" border="0" alt="image" width="244" height="236" /></a></p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/flex%e4%b8%ad%e8%8e%b7%e5%be%97datagrid%e4%b8%ad%e7%bc%96%e8%be%91%e5%89%8d%e5%90%8e%e7%9a%84%e6%95%b0%e6%8d%ae/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

