拖放值时更新总值datagrid - Adobe Flex [英] Update total value datagrid when drag drop values - Adobe Flex
本文介绍了拖放值时更新总值datagrid - Adobe Flex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从一个数据网格中拖放一个数值到另一个数据网格时,两个标签总数必须根据每个数据网格的值更新
然而,
$ b 代码:
<?xml版本= 1.0 >?;
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;
导入mx.events.DataGridEvent;
导入mx.events.DragEvent;
private function initApp():void {
dgA.dataProvider = new ArrayCollection([
{Expense:'Electricity',Value:300,minNo:100,maxNo:500 },
(费用:'Phone',值:200,minNo:50,maxNo:300},
(费用:'Contract A',值:5000,minNo:4000,maxNo:6000} ,
(费用:'Contract B',Value:6000,minNo:4500,maxNo:8500},
(费用:'Contract C',值:3000,minNo:2500,maxNo:3500}
]);
dgB.dataProvider = new ArrayCollection([]);
sumA();
$ b private function disableEditing(event:DataGridEvent):void {
if(event.columnIndex == 0)
{
event.preventDefault( );
public function sumA():void {
var sum:Number = 0;
for(var k:String in dgA.dataProvider){
sum + = dgA.dataProvider [k] ['Value'];
}
totalA.text = sum.toString();
public function sumB():void {
var sum:Number = 0;
for(var k:dgB.dataProvider中的字符串){
sum + = dgB.dataProvider [k] ['Value'];
}
totalB.text = sum.toString();
public function dragDropHandler(event:DragEvent):void {
sumA();
sumB();
}
]]>
< / fx:Script>
< s:HGroup>
< s:VGroup>
< mx:DataGrid id =dgA
allowMultipleSelection =true
dragEnabled =true
dropEnabled =true
dragMoveEnabled =true
dragDrop =dragDropHandler(event)>
< mx:columns>
< mx:DataGridColumn dataField =Expense/>
< mx:DataGridColumn dataField =Value/>
< / mx:columns>
< / mx:DataGrid>
< s:表格>
< s:FormItem label =Total>
< / s:FormItem>
< / s:表格>
< / s:VGroup>
< s:VGroup>
< s:标签文本=费用2/>
< mx:DataGrid id =dgB
allowMultipleSelection =true
dragEnabled =true
dropEnabled =true
dragMoveEnabled =true
editable =true
itemEditBeginning =disableEditing(event);
dragDrop =dragDropHandler(event)>
< mx:columns>
< mx:DataGridColumn dataField =Expense/>
< mx:DataGridColumn dataField =ValueeditorDataField =value>
< mx:itemEditor>
< fx:Component>
< mx:NumericStepper stepSize =1width =35height =20>
< fx:Script>
<![CDATA [
覆盖公共函数集数据(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:表格>
< s:FormItem label =Total>
< / s:FormItem>
< / s:表格>
< / s:VGroup>
< / s:HGroup>
< / s:Application>
解决方案
使用callLater dragDropHandler如下
public function dragDropHandler(event:DragEvent):void {
callLater(doTotal);
public function doTotal():void {
sumA();
sumB();
}
我测试过了,它对我来说工作的很好。 b $ b
I have two datagrid, and each has total label. This label sums all the values of each datagrid. When I drag and drop a value from one datagrid to another, the two label total must be updated according to the values of each datagrid.
However, a sum is delayed.
The code:
<?xml version="1.0"?>
<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;
import mx.events.DragEvent;
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([]);
sumA();
}
private function disableEditing(event:DataGridEvent):void {
if(event.columnIndex==0)
{
event.preventDefault();
}
}
public function sumA():void {
var sum:Number = 0;
for (var k:String in dgA.dataProvider){
sum += dgA.dataProvider[k]['Value'];
}
totalA.text = sum.toString();
}
public function sumB():void {
var sum:Number = 0;
for (var k:String in dgB.dataProvider){
sum += dgB.dataProvider[k]['Value'];
}
totalB.text = sum.toString();
}
public function dragDropHandler(event:DragEvent):void {
sumA();
sumB();
}
]]>
</fx:Script>
<s:HGroup>
<s:VGroup>
<s:Label text="Cost 1"/>
<mx:DataGrid id="dgA"
allowMultipleSelection="true"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
dragDrop="dragDropHandler(event)">
<mx:columns>
<mx:DataGridColumn dataField="Expense"/>
<mx:DataGridColumn dataField="Value"/>
</mx:columns>
</mx:DataGrid>
<s:Form>
<s:FormItem label="Total">
<s:Label id="totalA"/>
</s:FormItem>
</s:Form>
</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);"
dragDrop="dragDropHandler(event)">
<mx:columns>
<mx:DataGridColumn dataField="Expense"/>
<mx:DataGridColumn dataField="Value" editorDataField="value">
<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:Form>
<s:FormItem label="Total">
<s:Label id="totalB"/>
</s:FormItem>
</s:Form>
</s:VGroup>
</s:HGroup>
</s:Application>
解决方案
Use callLater() method to call the sum method from dragDropHandler as below
public function dragDropHandler(event:DragEvent):void {
callLater(doTotal);
}
public function doTotal():void{
sumA();
sumB();
}
I tested it and it is working fine for me.
这篇关于拖放值时更新总值datagrid - Adobe Flex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文