flex4.5 DataGrid控制某行不可编辑问题



flex4.5 DataGrid控制某行不可编辑。

网上关于flex4.5的DataGrid例子很少,自己做的时候也遇到了很多问题。

应用程序中的DataGrid:(要用自定义的itemEditor)

 

  1. <s:DataGrid id=”osinfoData” width=”100%” height=”100%” alternatingRowColors=”[#eeffff,#ffffff]“ editable=”true” dataProvider=”{infoproperties}”>
  2.     <s:columns>
  3.         <s:ArrayList>
  4.             <s:GridColumn  headerText=”名称” dataField=”name” editable=”false”/>
  5.             <s:GridColumn headerText=”值” dataField=”value” editable=”true” itemEditor=”com.control.itemeditor.DataGridEditItemEditor”/>
  6.         </s:ArrayList>
  7.     </s:columns>
  8. </s:DataGrid>

infoproperties列表格式:(edit控制该行是否可编辑)

[javascript] view plaincopy

  1. var infoproperties:ArrayCollection=new ArrayCollection();
  2. infoproperties.addItem({name:”id”,value:”1″,edit:false});
  3. infoproperties.addItem({name:”名称”,value:”1″,edit:true});
  4. infoproperties.addItem({name:”xml名称”,value:”1″,edit:true});
  5. infoproperties.addItem({name:”注释”,value:”1″,edit:true});
  6. infoproperties.addItem({name:”创建时间”,value:”2012-10-12 08:00:00″,edit:false});
  7. infoproperties.addItem({name:”创建人”,value:”me”,edit:false});
  8. infoproperties.addItem({name:”最后修改时间”,value:”2012-10-12 08:00:00″,edit:false});
  9. infoproperties.addItem({name:”最后修改人”,value:”me”,edit:false});

自定义DataGridEditItemEditor.mxml

  1. <?xml version=”1.0″ encoding=”utf-8″?>
  2. <s:GridItemEditor xmlns:fx=<a href=”http://ns.adobe.com/mxml/2009″>http://ns.adobe.com/mxml/2009</a> xmlns:s=”library://ns.adobe.com/flex/spark” xmlns:mx=”library://ns.adobe.com/flex/mx” clipAndEnableScrolling=”true”>
  3.     <fx:Script>
  4.         <![CDATA[
  5.             public var newValue:String;
  6.             override public function set data(value:Object):void{
  7.                 super.data=value;
  8.                 txt.text=data.value;
  9.                 txt.editable=data.edit;
  10.             }
  11.         ]]>
  12.     </fx:Script>
  13.     <s:TextInput id=”txt” alpha=”1″ width=”100%” height=”100%” change=”super.value = txt.text” updateComplete=”newValue=txt.text;”/>
  14. </s:GridItemEditor>

注意:txt.text,和txt.editable要在set data时设置,写在TextInput标签里,初始化的时候data是null,取不到其中的值