AdvancedDataGrid 数据字段刷新

发布于 2024-08-12 06:10:21 字数 3222 浏览 6 评论 0原文

我对 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>

I have a problem with an AdvancedDataGrid; i want the fields Actual and Estimate to change with the timer function but it doesn't work. It works only by refreshing all the adg with the collapse of the tree structure. I want that if the tree is "exploded" only actual and estimate fields refresh. Sorry for my uncorrect english.
Here's the code

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

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

从计时器的处理程序中调用 gc.source = dpCollection();。


更新:显然,< code>IGroupingCollection 不会自动检测组的更改,因此您必须在设置组属性后调用refresh()方法来更新视图。

似乎有解决此问题的方法 此处

You are not changing the dataProvider in the Timer handler. You are just calling the randomValues() method that just returns a number.

Call gc.source = dpCollection(); from the Timer's handler.


Update: Apparently, the IGroupingCollection does not detect changes to a group automatically, so you must call the refresh() method to update the view after setting the group property.

There seem to be a work around to this issue here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文