开发者

Flex DataGrid query

I need to write the following event.I have a Flex datagrid.When I click on a row I should fetch a particular column and call a remote EJB method.The Flex EJB bridge is working perfectly with BlazeDs.Here are my codes

<mx:DataGrid id="employees" x="100" y="50" dataProvider="{empList}" height="150" click='empHandler();'>
 <mx:columns>
    <mx:DataGridColumn  headerText="empid" dataField="empid" />   
开发者_JAVA百科 </mx:columns>
</mx:DataGrid>

My Employee structure empid:Number,firstname,lastname,email,image,password all are Strings. The table contains the list of empids.When I select a particular row I hit the EJB method which will return the whole Employee object.I am calling the remote method as follows

<mx:RemoteObject id="srv" showBusyCursor="true" destination="quizAppEJB"
       fault="mx.controls.Alert.show(event.fault.faultString, 'Error')">
   <mx:method name="checkLogin" result="empList=event.result"
        fault="mx.controls.Alert.show(event.fault.faultString)">
    <mx:arguments>
    <username>username.text</username>
    <password>password.text</password>
    </mx:arguments>
   </mx:method>

This is my empHandler method.

 private function empHandler():void 
    {
    Alert.show('hi');
    srv.getEmployeeDetails(empid);

    }

I am not sure how to set the empid that is present in the table

username.text password.text

employees.selectedItem.empid

I want to set the value empDetailList.employee.image as sorce for the image.I am not sure whether I am clear but will clarify if you hv any doubt.


Instead of click try to listen for itemClick event on your datagrid, passing event object as an argument of your handler:

<mx:DataGrid id="employees" x="100" y="50" dataProvider="{empList}"
    height="150" itemClick="empHandler(event)">

Event object - as an instance of mx.events.ListEvent - has rowIndex property which defines

The zero-based index of the item associated with the event.

Having that you can fetch item from your data provider:

private function empHandler(event:ListEvent):void{
    srv.getEmployeeDetails(empList.getItemAt(event.rowIndex).id);
}

Alternatively and much more easily you can just get selected item directly from datagrid

private function empHandler():void{
    srv.getEmployeeDetails(employees.selectedItem.id);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜