views:

39

answers:

1

As an alternative to binding an array collection to a data grid's data provider, could I assign the array collection as the data provider to the data grid on it's creation and everytime the array collection is updated execute invalidateProperties(); invalidateList(); to re-render the data grid?

Does my described approach make sense?

A: 

Does my described approach make sense?

Sort of. If you have an arrayCollection ( ac) defined using a get/set method, there is no reason you can't set the dataPRovider on your DataGrid in the set method, every time the data is changed.

If you do that, then you most likely will not have to update the properties or displayList of the DatGrid, because the mere fact of replacing the dataProvider will do it for you.

Something like this:

private var _ac : ArrayCollection;
public function get ac():ArrayCollection){
 return this._ac;
}

public function set ac(value:ArrayCollection){
 this._ac = value;
 this.dataGrid.dataProvider = this.ac;
}

Bingo, every time that the ac value is updated, so will the dataProvider on the DataGrid.

www.Flextras.com
@Flextras: The caveat is the collection is being modified item-by-item rather than as a whole collection, i.e. `_ac.addItem(obj);` Ideally, I'd like all the objects to be added/removed from the collection before (re)assigning it as the data grid's data provider. Is that possible via the getters/setters approach?
dank106
@dank106 I think understand better now. You're not changing the dataPRovider reference, but rather changing the collection that that reference points to. Is taht correct? The DataGrid should update automatically when items are added removed in a Collection. This has nothing to do with binding. It is because the DataGrid implements a collectionChange event handler. However, the DataGrid will not update if you modify properties in the objects in the collection. For that you'll have to do the relevant invalidation on the DataGrid.
www.Flextras.com
@Flextras: Yes, you're correct. I am looking for a more efficient way to handle the changes to the collection; I want to wait for all the changes in the collection to occur before forcing the grid to re-render. Also, thanks for pointing out the Data Grid implements the collection change handler; I was under the impression that binding was required.
dank106
You can check the code, but most likely the default collectionChange handler makes use of the component lifecycle; in which case a bunch of changes in succession will not update "all at once". However, you could always extend and override to change the default approach.
www.Flextras.com