PDA

View Full Version : DataGrid - distinct single event for data change


vivoices
05-01-2009, 01:40 PM
I am looking for an event that a DataGrid dispatches ONCE when the data in its DataProvider changes.
I set up a test DataGrid that displays the row data of a "clicked item" directly from the ArrayCollection being assigned as the DataProvider.dg.addEventListener( ListEvent.ITEM_CLICK, itemClick );I spent hours looking for an event that is dispached once from either the DataGrid or the ArrayCollection to react to that change of data. NeitherdataToDisplay.addEventListener( FlexEvent.DATA_CHANGE, dataChange );nordg.addEventListener( FlexEvent.DATA_CHANGE, dataChange );are dispatching.
Events like "DataGridEvent.ITEM_EDIT_BEGIN", "DataGridEvent.ITEM_EDIT_BEGINNING" or "DataGridEvent.ITEM_EDIT_END" are unreliable with the default and my custom ItemRenderers.
Other events relate only to the display aspect of the DataGrid and not the underlying data.

Any ideas?

Thanks,
David

JeTSpice
05-01-2009, 04:23 PM
perhaps removing the event listener after it is dispatched once?

wvxvw
05-01-2009, 06:07 PM
Sorry, there was a discussion about it, but I couldn't find that thread... but there should be a way to:
- prevent ArrayCollection from autorefreshing.
- prevent it from dispatching a "change" even on every added / removed item (even when you are adding / removing multiple items at a time).
- finally make it dispatch a sort of "multiple change" event...

Well, honestly, I'd simply turn off autoupdates and update array collection manually (through the ArrayCollection#source) when I need...

vivoices
05-01-2009, 06:55 PM
I think, I will write my own RowData dynamic class that dispatches all events I need (get and set functions) in an all-static GlobalEvents class.
The data for the DataGrid will be built likedataToDisplay = new ArrayCollection();
dataToDisplay.addItem( new RowData() ); . . . thus getting a (hopefully) rock-solid event behaviour dispached right at the datasource.

All the tests I was running today on the DataGrid events gave me the impression that the DataGrid is still a very messy object.

David

vivoices
05-05-2009, 03:09 PM
The solution is simpler than I thought: ObjectProxy did the job.dataToDisplay = new ArrayCollection();
rowItem = new Object();

// populate rowItem with data

rowProxy = new ObjectProxy( rowItem, "row" + c )
rowProxy.addEventListener( PropertyChangeEvent.PROPERTY_CHANGE, dataChange );
dataToDisplay.addItem( rowProxy );
dataGrid.dataProvider = dataToDisplay;

private function dataChange( event:PropertyChangeEvent ):void
{
// data change handeling code
}now a reliable, single event is fired directly from the data source when a value changes. I did not try to wrap the whole ArrayCollection in a single ObjectProxy yet.