English 中文(简体)
Flex: How can I Make changes to an ArrayCollection bound to data grid live?
原标题:

I have an ArrayCollection bound to an editable DataGrid, another component needs to know when the ArrayCollection changes (as a result of changes in the DataGrid) so it can also update itself, so is listening to the COLLECTION_CHANGE event of the ArrayCollection.

The problem is that the DataGrid only updates the ArrayCollection when the row being edited losses focus. This is not good for my app as a user could edit a column on a row and not click elsewhere on the table for a long time (causing the row to lose fucus), therefore the changes won t have propagated to the other parts of the application.

How can I make the data grid inform the ArrayCollection of a change every time there is a keyup event on a text input instead of every time a row looses focus?

Cheers,

Chris

最佳回答

I would add the handler to the component used to edit the value instead of to the ArrayCollection. Example:

<mx:DataGridColumn dataField="name" headerText="Name" itemEditor="{nameEditor}" editorDataField="selectedItem" />

Then this is used to edit the value:

<mx:Component id="nameEditor">
    <mx:ComboBox dataProvider="{outerDocument.names}" change="outerDocument.setNameField(event)" close="outerDocument.setNameField(event)" />
</mx:Component>

And this is the handler for the change (and close) event:

public function setDestinationField(event:*):void {
    var destination:String = (event.target as ComboBox).selectedLabel;
    if (destination ===   ) {
        delete _gridData[_currentlyEditedRowIndex].destination;
    } else {
        _gridData[_currentlyEditedRowIndex].destination = destination;
    }
}

_currentlyEditedRowIndex is set by adding this to the grid:

itemEditBegin="beginEdit(event);"
问题回答

Thanks Gabriel you put me on the right path. I will post here my final solution in case anyone else needs to do the same thing in the future.

  <mx:DataGridColumn headerText="Title" width="300" dataField="title">
    <mx:itemEditor>
      <mx:Component>
        <mx:TextInput change="data.title = text" />
      </mx:Component>
    </mx:itemEditor>
  </mx:DataGridColumn>

Now whenever the text is changed in the input the ArrayCollection being used as the data provider is also updated, so other components listen for COLLECTION_CHANGE events.





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签