在表格中指定属性itemEditEnd="adgrid_itemEditEndHandler(event)"利用方法进行验证。
<mx:DataGrid id="bsManualGrid"
itemEditEnd="validateItem(event)" //表格编辑后调用
dataProvider="{_gridData}" editable="true"
sortableColumns="false">
<mx:columns>
</mx:columns>
</mx:DataGrid>
private function validateItem(event:DataGridEvent):void{
if (event.reason == DataGridEventReason.CANCELLED){
return;
}
var input:TextInput=TextInput(bsManualGrid.itemEditorInstance);
var newData:String=TextInput(event.currentTarget.itemEditorInstance).text;
//如果商品查询的输入则验证非空
if ((event.dataField == "vulCount" || event.dataField == "weakPwdCount"
|| event.dataField == "congruentRate")
&& StringUtil.trim(newData).length <= 0){
event.preventDefault();
input.errorString="不能为空!";
}
//如果是数量则验证必须为数字
if ((event.dataField == "vulCount" || event.dataField == "weakPwdCount")
&& isNaN(Number(StringUtil.trim(newData)))){
event.preventDefault();
input.errorString="该项必须为数字!";
return;
}
}
【注】DataGridEvent的一些特殊参数:
event.dataField -----------表格属性的编码
event.reason ------The reason the itemEditEnd event was dispatched.
* Valid only for events with type ITEM_EDIT_END //只验证ITEM_EDIT_END类型的event
* The possible values are defined in the DataGridEventReason class.
常用来 如上面as代码中,来判断编辑完成的状态原因