开发者

How to remove row from datagrid?

开发者 https://www.devze.com 2023-01-18 10:47 出处:网络
I have a datagrid from which I\'d like be able to remove rows at will. Below is the component item renderer I\'m putting together in order to achieve desired result, but there has to be a better way t

I have a datagrid from which I'd like be able to remove rows at will. Below is the component item renderer I'm putting together in order to achieve desired result, but there has to be a better way to access the data provider of the "parent" data grid. Anyone have any ideas/suggestions?

<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" 
focusEnabled="true">
<fx:Script>
<![CDATA[

public function deleteRow(event:MouseEvent):void 
{
var dataGrid:DataGrid = event.target.parent.parent.parent; // There has to be a better way to get the data grid then climbing up the entity chain like this.
    dataGrid.dataProvider.removeItemAt(dataGrid.dataProvider.getItemIndex(data开发者_运维百科));
}
]]>
</fx:Script>
<s:Button label="Delete" click="deleteRow(event)"/>
</s:MXDataGridItemRenderer>


You don't...

public function deleteRow( event : MouseEvent = null ) : void {
    var delEvent : DynamicEvent = new DynamicEvent( "deleteEvent", true );
    delEvent.dataToDelete = data;
    dispatchEvent( delEvent );
}

then in the class with your DG your DG.

<mx:DataGrid id="foo" dataProvider="{someDP}" />
foo.addEventListener( "deleteEvent", updateDP );
private function updateDP( event : DynamicEvent ) : void {
    foo.dataProvider.removeItem( event.dataToDelete );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消