AdvancedDataGrid dataFields刷新

时间:2009-11-27 13:35:43

标签: flex air random timer advanceddatagrid

我有一个AdvancedDataGrid的问题;我希望使用计时器功能更改“实际”和“估计”字段,但它不起作用。它只能通过刷新树结构的所有adg来工作。我希望如果树“爆炸”只有实际和估计字段刷新。抱歉我的英语不正确。 这是代码

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication initialize="init();" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.utils.ArrayUtil;
            import mx.collections.*;
            import flash.utils.Timer;
            import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
            [Bindable]
            public var randomNumber:Number = new Number
            public function randomValues():Number
            {
            randomNumber=Math.random()*100
            randomNumber*=100
            randomNumber=Math.round(randomNumber)
            randomNumber/=100
            trace(randomNumber)
            return randomNumber
            }   
            public var timer:Timer = new Timer(20);
            public function timing():void{
            timer.addEventListener(TimerEvent.TIMER,function(event:Event):void{randomValues()});
            }
            [Bindable]
            public var dpFlat:ArrayCollection = new ArrayCollection;
            public function dpCollection():ArrayCollection
            {
            dpFlat= new ArrayCollection([
            {Continente:"Europa", Paese:"Italia", Actual:randomValues(), Estimate:randomValues()},
            {Continente:"Europa", Paese:"Germania", Actual:randomValues(), Estimate:randomValues()}
                ]);
            return dpFlat;
            }

            public function init():void{
            dpCollection()
            randomValues()  
            }


        ]]>
        </mx:Script>
        <mx:AdvancedDataGrid horizontalScrollPolicy="on" columnWidth="100" resizableColumns="false" id="myADG" width="469" height="223" color="0x323232" initialize="gc.refresh();">        
                <mx:dataProvider>
                <mx:GroupingCollection id="gc" source="{dpCollection()}">
                    <mx:grouping>
                        <mx:Grouping>
                            <mx:GroupingField name="Continente"/>
                            <mx:GroupingField name="Paese"/>
                        </mx:Grouping>
                    </mx:grouping>
                </mx:GroupingCollection>
                </mx:dataProvider>        

            <mx:columns>
                <mx:AdvancedDataGridColumn dataField="Continente"/>
                <mx:AdvancedDataGridColumn dataField="Paese"/>
                <mx:AdvancedDataGridColumn id="act" dataField="Actual"/>
                <mx:AdvancedDataGridColumn id="est" dataField="Estimate"/>


            </mx:columns>
    </mx:AdvancedDataGrid>
    <mx:TextArea text="{randomNumber}" x="477" y="10"/>
    <mx:Button click="timing()" x="10" y="231" label="Start timing function"/>
    <mx:Button click="timer.start()" x="161" y="231" label="Start the time"/>
    <mx:Button click="timer.stop()" x="275" y="231" label="Stop the time"/>
</mx:WindowedApplication>

1 个答案:

答案 0 :(得分:0)

您没有更改dataProvider处理程序中的Timer。您只是调用只返回数字的randomValues()方法。

从Timer的处理程序中调用gc.source = dpCollection();


更新:ApparentlyIGroupingCollection未自动检测到对组的更改,因此您必须在设置组属性后调用refresh()方法更新视图。

似乎有一个解决此问题here

的工作