Search code examples
apache-flexdatagridflex4.5itemrenderer

ArrayCollection not updated via ItemRenderer (CheckBox) in Flex


I am having problems to update my ArrayCollection which initially populates my datagrid. In my case the dataprovider consists of True and False as String. These come from my database. I set the dataProvider of my datagrid to the ArrayCollection and I render the field in a checkBox in the datagrid. The checkbox is ticked correctly upon display. But if I tick/untick the checkbox again and try to take a look at the ArrayCollection, I notice that the ArrayCollection remains unchanged. I still get the old values.

Can someone guide me through as to what I am missing in my code? Below is the code for my datagrid.

<mx:DataGrid id="myDataGrid" dataProvider="myArrayCollection" fontSize="9" enabled="true" x="20" y="20" width="217" height="60">
    <mx:columns>
        <mx:DataGridColumn rendererIsEditor="true" editorDataField="selected" width="20" headerText="MyField" dataField="MY_FIELD">
            <mx:itemRenderer>
                <fx:Component>
                    <mx:HBox horizontalAlign="left">
                        <s:CheckBox selected="{data.MY_FIELD == 'false' ? false : true}" horizontalCenter="0"/>
                    </mx:HBox>
                </fx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

Solution

  • Try replacing your CheckBox with this:

    <s:CheckBox selected="{data.MY_FIELD == 'false' ? false : true}" change="data.MY_FIELD = !data_MY_FIELD" horizontalCenter="0"/>
    

    This should flip the value whenever the user changes the state of the CheckBox.