我有兩個數據網格,並且可以從datagrid A拖放任何項目以放入數據網格B.在datagrid B中,我可以編輯這些值,並且這些值具有最小值和最大。這些值具有貨幣格式。但是,我遇到了一個問題:當我編輯datagrib B中放置的項目中的值時,該值會自動更改爲最小值。在datagrid中編輯時保留當前值 - Adobe Flex
正確的是在編輯時保持當前值。
有什麼想法?
代碼:
<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"
width="650"
creationComplete="initApp();">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.DataGridEvent;
private function initApp():void {
dgA.dataProvider = new ArrayCollection([
{Expense:'Electricity', Value:300, minNo: 100, maxNo: 500},
{Expense:'Phone', Value:200, minNo: 50, maxNo: 300},
{Expense:'Contract A', Value:5000, minNo: 4000, maxNo: 6000},
{Expense:'Contract B', Value:6000, minNo: 4500, maxNo: 8500},
{Expense:'Contract C', Value:3000, minNo: 2500, maxNo: 3500}
]);
dgB.dataProvider = new ArrayCollection([]);
}
private function disableEditing(event:DataGridEvent):void {
if(event.columnIndex==0)
{
event.preventDefault();
}
}
protected function LabelFormatter(item:Object, column:DataGridColumn):String
{
return MoedaFormatter.format(item.Value);
}
]]>
</fx:Script>
<fx:Declarations>
<mx:CurrencyFormatter id="MoedaFormatter" precision="2" currencySymbol="R$" alignSymbol="left" decimalSeparatorTo="," decimalSeparatorFrom="," thousandsSeparatorFrom="." thousandsSeparatorTo="."/>
</fx:Declarations>
<s:HGroup>
<s:VGroup>
<s:Label text="Cost 1"/>
<mx:DataGrid id="dgA"
allowMultipleSelection="true"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true">
<mx:columns>
<mx:DataGridColumn dataField="Expense"/>
<mx:DataGridColumn dataField="Value" labelFunction="LabelFormatter"/>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
<s:VGroup>
<s:Label text="Cost 2"/>
<mx:DataGrid id="dgB"
allowMultipleSelection="true"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
editable="true"
itemEditBeginning="disableEditing(event);">
<mx:columns>
<mx:DataGridColumn dataField="Expense"/>
<mx:DataGridColumn dataField="Value" editorDataField="value" labelFunction="LabelFormatter">
<mx:itemEditor>
<fx:Component>
<mx:NumericStepper stepSize="1" width="35" height="20">
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
{
super.data = value;
if (value && value.hasOwnProperty("minNo")) {
minimum = value.minNo;
}
if (value && value.hasOwnProperty("maxNo")) {
maximum = value.maxNo;
}
}
]]>
</fx:Script>
</mx:NumericStepper>
</fx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</s:HGroup>
提前感謝!
非常好!!!!它解決了我的問題!謝謝! – Marcel