Flex中获得DataGrid中编辑前后的数据

问题:

在使用DataGrid进行数据编辑时, 我们不可避免的需要对数据的输入进行检验, 修正等错误.

解决方法:

监听DataGrid的editEnd事件:DataGridEvent.ITEM_EDIT_END.改事件中包含有正在编辑的DataGridColumn[列名], 编辑前的数据, 编辑结束后的数据, 等等

具体实现:

1. 获得当前编辑的DataGridColumn;  2. 获得编辑前后的数据;

	/**
	 * 响应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()来阻止默认行为
			}
	 	}......
	 }

抓图:

image

This entry was posted in Flex and tagged , , . Bookmark the permalink.

4 Responses to Flex中获得DataGrid中编辑前后的数据

  1. 网友 says:

    我好像来过你的博客了。不过既然来了。给你留点东西吧 (*^__^*) 嘻嘻……

  2. LiGL says:

    To:siaaa.com网友
    谢谢~

  3. wiz says:

    获得当前的列,然后获得未修改前的数据
    之后下面这句话有点看不懂,能不能麻烦您帮我解释下啊?我现在要做的就是修改datagrid,然后更新到数据库?
    _dataGrid.itemEditorInstance[columnLocale.editorDataField]

    谢谢,不胜感激

  4. 来了就得留下些东西 ~~~

    看不懂 支持你。。

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>