我有两个数据网格,可以将任何项目从数据网格A拖放到数据网格B中。在数据网格B中,我可以编辑值,这些值具有最小值和最大值限制。值具有货币格式。但是,我遇到了一个问题:当我在datagrib B中删除的项目中编辑一个值时,该值会自动更改为最小值。
正确的是在编辑时保持当前值。
有什么想法吗?
代码:
<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>
提前致谢!
答案 0 :(得分:2)
修改itemeditor中的set data方法,如下所示
override public function set data(value:Object):void {
super.data = value;
if (value && value.hasOwnProperty("Value")) {
super.value = value.Value;
}
if (value && value.hasOwnProperty("minNo")) {
minimum = value.minNo;
}
if (value && value.hasOwnProperty("maxNo")) {
maximum = value.maxNo;
}
}
我自己测试了这个并且工作正常
答案 1 :(得分:1)
当您从dgA中删除项目时,您将删除包含minNo和maxNo属性的对象,并且连接到data of data属性的脚本会指定项呈示器的最小和最大属性。
因此,只需删除嵌套在dgB中的标记或对其进行评论。