Add a button dyeing device to the GridColumn column of the DataGrid.

Source: Internet
Author: User

In a project, a function such as effect is required:

 


You need to add a button to the GridColumn column of the DataGrid:

1. Declare a spark DataGrid first. Add the button advertiser and the red code part to the last column.


[Html]
<S: DataGrid id = "DataGrid2" verticalScrollPolicy = "on" horizontalScrollPolicy = "on" width = "100%" height = "100%" minHeight = "200" skinClass = "com. tm. skin. dataGridSkin ">
<S: columns>
<S: ArrayList>
<S: GridColumn headerText = "region name" dataField = "areaName"/>
<S: GridColumn headerText = "region NO" dataField = "areaNo"/>
<S: GridColumn headerText = "whether to use" dataField = "isUse" labelFunction = "isUseValue"/>
<SPAN style = "COLOR: # ff0000"> <s: GridColumn itemRenderer = "com. tm. renderer. OperateItem" editable = "false"/> </SPAN>
</S: ArrayList>
</S: columns>
</S: DataGrid>

<S: DataGrid id = "DataGrid2" verticalScrollPolicy = "on" horizontalScrollPolicy = "on" width = "100%" height = "100%" minHeight = "200" skinClass = "com. tm. skin. dataGridSkin ">
<S: columns>
<S: ArrayList>
<S: GridColumn headerText = "region name" dataField = "areaName"/>
<S: GridColumn headerText = "region NO" dataField = "areaNo"/>
<S: GridColumn headerText = "whether to use" dataField = "isUse" labelFunction = "isUseValue"/>
<S: GridColumn itemRenderer = "com. tm. renderer. OperateItem" editable = "false"/>
</S: ArrayList>
</S: columns>
</S: DataGrid> 2 There are two buttons in the GridItemRenderer class of the Declaration dyeing tool, and a custom event is added to the two buttons for distribution:


[Java]
<Fx: Script>
<! [CDATA [
Import com. tm. event. OperateEvent;
Private function removeItem (): void {
Trace (data );
Var removeEvent: OperateEvent = new OperateEvent (OperateEvent. REMOVE, data );
This. dispatchEvent (removeEvent );
}

Private function updateItem (): void {
Var updateEvent: OperateEvent = new OperateEvent (OperateEvent. UPDATE, data );
This. dispatchEvent (updateEvent );
}
]>
</Fx: Script>

<S: Button label = "edit" click = "updateItem ()"/>
<S: Button label = "delete" click = "removeItem ()"/>

<Fx: Script>
<! [CDATA [
Import com. tm. event. OperateEvent;
Private function removeItem (): void {
Trace (data );
Var removeEvent: OperateEvent = new OperateEvent (OperateEvent. REMOVE, data );
This. dispatchEvent (removeEvent );
}

Private function updateItem (): void {
Var updateEvent: OperateEvent = new OperateEvent (OperateEvent. UPDATE, data );
This. dispatchEvent (updateEvent );
}
]>
</Fx: Script>
 
<S: Button label = "edit" click = "updateItem ()"/>
<S: Button label = "delete" click = "removeItem ()"/> 3. The Custom Event is as follows:


[Java]
Public class OperateEvent extends Event
{
Public var data: Object;
Public static const REMOVE: String = "remove ";
Public static const UPDATE: String = "update ";
Public function OperateEvent (type: String, data: Object, bubbles: Boolean = true, cancelable: Boolean = false)
{
This. data = data;
Super (type, bubbles, cancelable );
}
}

Public class OperateEvent extends Event
{
Public var data: Object;
Public static const REMOVE: String = "remove ";
Public static const UPDATE: String = "update ";
Public function OperateEvent (type: String, data: Object, bubbles: Boolean = true, cancelable: Boolean = false)
{
This. data = data;
Super (type, bubbles, cancelable );
}
}
4 finally, we need to add the listening method for custom events to the creationComplete Initialization Method in the main program, that is, the DataGrid class using spark:


[Html]
Protected function CompleteHandler (event: FlexEvent): void
{
<SPAN style = "COLOR: # cc0000"> maid (OperateEvent. REMOVE, removeUI );
DataGrid2.addEventListener (OperateEvent. UPDATE, updateUI); </SPAN>
ServerPagingBar1.dataGrid = maid;
// Flex paging
ServerPagingBar1.pagingFunction = pagingFunction;
}

Protected function CompleteHandler (event: FlexEvent): void
{
DataGrid2.addEventListener (OperateEvent. REMOVE, removeUI );
DataGrid2.addEventListener (OperateEvent. UPDATE, updateUI );
ServerPagingBar1.dataGrid = maid;
// Flex paging
ServerPagingBar1.pagingFunction = pagingFunction;
} 5. After listening to these two events, write the handler: removeUI Delete, update and edit as follows:


[Html]
Protected function updateUI (event: OperateEvent): void
{
Var areaUI: AreaUI = PopUpManager. createPopUp (this, AreaUI) as AreaUI;
AreaUI. state = "update ";
AreaUI. areaVo = event. data as AreaVo;
PopUpManager. centerPopUp (areaUI );
}

Protected function updateUI (event: OperateEvent): void
{
Var areaUI: AreaUI = PopUpManager. createPopUp (this, AreaUI) as AreaUI;
AreaUI. state = "update ";
AreaUI. areaVo = event. data as AreaVo;
PopUpManager. centerPopUp (areaUI );
} [Html] view plaincopyprint? Protected function removeUI (event: OperateEvent): void
{
Alert. okLabel = 'true ';
Alert. cancelLabel = 'cancel ';
Alert. show ("are you sure you want to delete this record", "Are you sure you want to delete this record? ", Alert. OK | Alert. CANCEL, this, removeFunction );
RecId = event. data. recNo;

}

Protected function removeUI (event: OperateEvent): void
{
Alert. okLabel = 'true ';
Alert. cancelLabel = 'cancel ';
Alert. show ("are you sure you want to delete this record", "Are you sure you want to delete this record? ", Alert. OK | Alert. CANCEL, this, removeFunction );
RecId = event. data. recNo;

} End!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.