开发者

Flex components with dynamic data update

I need to push real time data to a Flex GUI (Data grid), but each time new data is pushed to the grid, it's losing its previous state.

Example:

  1. if I scrolled to the right, after the next update scrolls come back to the default position, that is, left
  2. if I am selecting any row, it's gett开发者_运维问答ing unselected just after update.

Is there a way to maintain the state?

I am using Flex 3. I can move to Flex 4 if it helps.


How do you set the data? Do you change the DataGrid dataProvider with a new collection of objects ? Because, from the behavior described by you this may be the case.

The solution would be instead changing the dataProvider of the DG. Each time, you should just update the values in the collection which is assigned as data provider.

For example,

[Bindable]
var myDataCollection:ArrayCollection = new ArrayCollection([0,1,2,3,4]);

// Handle creation complete.
private function onCreationComplete():void
{
   initDG();
}

// Init DG data provider just once.
private function initDG(data:ArraCollection):void
{
   myDG.dataProvider = data;
}

private function updateDG_Method_1(row:int, value:int):void
{
    var data:ArrayCollection = myDG.dataProvider as ArrayCollection;

    if(data && data.length > row)
    {
        data[row] = value;
    }

    // We can force refresh if not not done automatically.
    myDG.invalidateList();
    myDG.validateNow();
}

private function updateDG_Method_2(row:int, value:int):void
{
    if(myDataCollection && myDataCollection.length > row)
    {
        myDataCollection[row] = value;
    }

    // We can force refresh if not not done automatically.
    myDG.invalidateList();
    myDG.validateNow();
}

Please ignore/correct any typo .. since I did not test this :))

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜