about Flex DataGrid edit
Summary(¸ÅÊö)£º Adobe Flex µÄ dataGrid ÓкÜÇ¿´óµÄ¹¦ÄÜ£¬±ÈÈçItemRenderer,headerRendererµÈ£¬¿ÉÒÔ·½±ãµØÊµÏÖ×Ô¼ºÏëÒªµÄ¹¦ÄÜ¡£µ«¶ÔdataGridÖ±½Ó±à¼²¢±£´æµ½Service¶Ë£¬¾ÍÓеãÂé·³ÁË¡£
Requirement(ÐèÇó)£º ¶ÔdataGrid½øÐе¥Î»¸ñ±à¼£¬ÈôÓб仯£¬±£´æµ½Service; ·ñÔò²»±£´æ¡£
Solution(½â¾ö·½°¸): ÔËÓÃDataGrid µÄ itemEditBegin ʼþ¡¢itemFocusOut ʼþ¡£
1. when the itemEditBegin is dispatched, the event handler should save this cell value as old value.(±à¼Ç°±£´æ¾ÉÖµ)
2. when the listener of itemFocusOut is responding, you should check the current cell to the old value. If it's value have changed, you should save the new value to Service.(±à¼ºóÅжϣ¬ÊÇ·ñ¸ü¸Ä¡£)
Example(Àý×Ó) as follow:
<mx:Script>
<![CDATA[
private var oldValueOfEditedItem: CreditVO;
private function creditDGEditBegin(event: DataGridEvent): void {
oldValueOfEditedItem = (event.itemRenderer.data as CreditVO).clone() as CreditVO;
}
private function editedItemChanged(newValue: CreditVO): Boolean {
return (newValue.amount != oldValueOfEditedItem.amount)||
(newValue.description != oldValueOfEditedItem.description);
}
private function creditDGEditEnd(event: DataGridEvent): void {
var newValue: CreditVO = event.itemRenderer.data as CreditVO;
if (editedItemChanged(newValue)) {
dispatchEvent(new UpdateCreditEvent(newValue))
}
}
]]>
&
Ïà¹ØÎĵµ£º
ǰһÕóÔÚÂÛ̳ÉÏ¿´µ½Ò»¸öÐֵܣ¬ÏëÔÚFlex ChartÖÐΪͼÀýÉèÖÃ3DЧ¹û,½ü¼¸Ìì²éÕÒÁËЩ×ÊÁÏ£¬¶¯ÊÖ×öÁ˸öDEMO¹©´ó¼Ò²Î¿¼!
DEMOÑÝʾµØÖ·http://xingjunli.webs.com/flash/flexChartDemo.swf,ÏÈÀ´¸öͼƬ¿´¿´×îÖÕЧ¹û:
Ïà¹ØÖªÊ¶µã
......
ÔÚflexµÄdataGridÖУ¬ºÜ¶àÇé¿öÏÂÁÐÊÇÐèҪǶÈëÆäËûµÄ¿ØÖƵ쬱ÈÈ磺checkbox,comboxµÈ£¬´ËʱÐèÒªÀûÓÃdataGridµÄÈçϹ¦ÄÜ£º
1.datagrid±à¼¹¦Äܼò½é
µ±ÎÒÃǵã»÷datagridÖеÄÒ»¸öµ¥Ôª¸ñ½øÐбà¼Ê±£¬¿É½áºÏʹÓÃһЩ×é¼þ£¬RadioButtonGroup¡¢checkbox¡¢ComboBoxµÈ
datagridµÄ±à¼¹¦Äܱ ......
ºÜ¶à¿ª·¢ÈËÔ±¶¼ÖªµÀÈçºÎʹÓÃʼþ»úÖÆ£¬µ«È´²»Àí½âʼþ»úÖÆµÄ»ù±¾¹¤×÷ÔÀí¡£ÔÚÕâÀïÎÒÃÇ̽ÌÖÒ»ÏÂActionScript 3µÄʼþ»úÖÆ(ÎÞÂÛÊÇÐÂÊÖ»¹ÊÇÀÏÊÖ£¬ÎÒÏàÐÅ¿´µ½×îºó¿Ï¶¨¶ÔÄãÓÐËù°ïÖú )¡£
1. Ê×ÏÈÀ´¿´Ò»ÏÂʼþ»úÖÆÖеö»ù±¾¸ÅÄ
event objects(ÕâÀïÎÒÃǹÃÇÒ½ÐËüʼþ¶ÔÏó)£ºËùÓеÄʼþ¶ÔÏó¶¼ÊÇflash.events.Event»òÕ߯ä×ÓÀà¡ ......
ÉÏÃæÊÇÒ»¸öflex×öµÄÑ¡Ôñ£¬Ö÷ҪѧϰÊý¾Ý Model¸úDateGridµÄÓ÷¨ ¹þ£¬Ô´ÂëÈçÏ£º
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="12">
<mx:Model id="books">
<datas>
<book>
  ......
·µ»ØÊý¾ÝµÄ¸ñʽresultFormatÓм¸ÖÖÀàÐÍ£¬object¡¢array¡¢xml¡¢flashvars¡¢textºÍe4x£¬Ä¬ÈϵÄÉèÖÃΪobject¡£
RESULT_FORMAT_ARRAY : String = "array"
[] ½á¹û¸ñʽ“array”Óë“object”ÏàËÆ£¬µ«ÊÇÆä·µ»ØµÄֵʼÖÕΪÊý×飻ÕâÑù£¬Èç¹û´Ó½á¹û¸ñʽ“object”·µ»ØµÄ½á¹ûÉв»ÊÇÊý×飬Ôò½«°Ñ¸ÃÏî ......