Wednesday, May 5, 2010

Flex Actionscript GoodNess: Updating Datagrid Display when Model(ArrayCollection) changes

Normally, making the dataProvider bindable makes sure, that if the underlying VO(Value Object) changes, the changes are reflected in the dataGrid.
But In case if the VO used cannot be made Bindable it becomes a problem, for e.g if the VO is a Dictionary Object.
In that case we need to notify the listeners of ArrayCollection that one of the VOs has changed, following code demostrates that.

var myDataArray:ArrayCollection = new ArrayCollection()

Lets Create the VOs to add to this collection
var empArr:Array = new Array()
var emp1:Dictionary = new Dictionary() ="john"

var emp2:Dictionary = new Dictionary() ="richard"

myDataArray = new ArrayCollection(empArr)

//Now lets set the dataProvider to the DataGrid

Now lets say if I go and update the emp1 Object, the value needs to get updated in
the DataGrid, but it will not unless I call itemUpdated() on the ArrayCollection.

Here is how I updated the DataGrid"UpdatedJohn"
myDataArray.itemUpdated(emp1) //And that will do the trick

Done!! Hurray!!

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes