Charles-Olivier Dion
Charles-Olivier Dion

Reputation: 21

Remove multiple rows in a Flex Spark datagrid

I want to delete all selected rows in a Spark datagrid.

This code below accounts for the Vector indices but I cannot get it to work. It does not throw out any errors.

What am I doing wrong?

public function deleteItem(event:MouseEvent):void{     
    var sIndices:Vector.<int> = arrayGrid.selectedIndices;
    sIndices.sort(Array.NUMERIC); 

    for(var index:int = sIndices.length-1; index>=0; index--) {
        arrayColl.removeItemAt(sIndices[index]);
    }       
    arrayColl.refresh();
} 

private function convertDateFormat(item:Object,column:GridColumn):String {
    return simpleDate.format(item.itemStartDate);simpleDate.format(item.itemEndDate);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" >
    <s:Button label="Remove Selected Items"/>       
    <s:Button label="Add New Entry" click="newItem()"/>     
    <search:searchBar id="SearchBar" searchListCollection="{arrayColl}"
                      dataGrid="{arrayGrid}"/>
    <s:DataGrid id="arrayGrid" width="100%" height="100%" dataProvider="{arrayColl}" 
                selectionMode="multipleRows" doubleClickEnabled="true">
        <s:columns>
            <s:ArrayList>               
                <s:GridColumn dataField="projectName" headerText="Project Name" />
                <s:GridColumn dataField="tag" headerText="Priority Code" />
                <s:GridColumn width="180" dataField="itemStartDate" 
                      labelFunction="convertDateFormat" headerText="Start Date"/>
                <s:GridColumn width="180" dataField="itemEndDate"  
                      labelFunction="convertDateFormat" headerText="End Date"/>
                <s:GridColumn dataField="notes" headerText="Notes"/>
                <s:GridColumn width="100" dataField="colorCode" headerText="Color HEX"/>
            </s:ArrayList>
        </s:columns>
    </s:DataGrid>

Upvotes: 0

Views: 367

Answers (1)

Juanpe
Juanpe

Reputation: 446

It looks like you forgot to call the deleteItem method.

<s:Button label="Remove Selected Items" click="deleteItem(event)"/>

Upvotes: 1

Related Questions