user120118
user120118

Reputation: 65

Selecting a Checkbox and deleting a data grid row in Flex

I am trying to implement the following :

  1. First column of datagrid has a checkbox.
  2. Select checkboxes, and then delete the datagrid column.
  3. Dynamically, add checkbox when row is added dynamically.
  4. Do not show check box if now data in row.

Can someone give some guidance ?

Upvotes: 0

Views: 11227

Answers (2)

Domnic
Domnic

Reputation: 3867

In itemdatabound u should give enabled as false in particular cell....

Upvotes: 0

Phil C
Phil C

Reputation: 980

I am assuming you want to delete a row and not a column. The following works

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="vertical">
    <mx:Script>
        <![CDATA[
            import mx.events.IndexChangedEvent;
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;

            [Bindable]
            private var ac:ArrayCollection=new ArrayCollection([{name: "John", shouldDelete: true}, {name: "Joe", shouldDelete: false}, {name: "Jill", shouldDelete: false}])


            private function deleteRows()
            {
                for each (var row:Object in ac)
                {
                    if (row.shouldDelete == true)
                    {
                        var i:int=ac.getItemIndex(row);
                        ac.removeItemAt(i);
                    }
                }
            }
        ]]>
    </mx:Script>

    <mx:VBox>
        <mx:DataGrid id="dg"
                     dataProvider="{ac}">
            <mx:columns>
                <mx:DataGridColumn dataField="name">

                </mx:DataGridColumn>
                <mx:DataGridColumn id="col2"
                                   editorDataField="selected"
                                   rendererIsEditor="true"
                                   dataField="data.shouldDelete">
                    <mx:itemRenderer>
                        <mx:Component>
                            <mx:CheckBox label="Test"
                                         selected="{data.shouldDelete}"
                                         change="data.shouldDelete=selected"/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>

            </mx:columns>

        </mx:DataGrid>
        <mx:Button label="delete"
                   id="deleteBtn"
                   click="deleteRows()"/>

    </mx:VBox>
</mx:Application>

Upvotes: 3

Related Questions