Populating a cfgrid with Flash Remoting

As a follow up of my last post, I made an example on how to populate a cfgrid with Flash Remoting.
The basic difference is that now the ColdFusion component returns a query instead of a string. The important part in the ActionScript code is how we set the data to the datagrid. To show the effect, I create a cfgrid and populate it with an empty query, so that when I call the component, I can see the data loaded.


As a follow up of my last post, I made an example on how to populate a cfgrid with Flash Remoting.
The basic difference is that now the ColdFusion component returns a query instead of a string. The important part in the ActionScript code is how we set the data to the datagrid. To show the effect, I create a cfgrid and populate it with an empty query, so that when I call the component, I can see the data loaded.

The main change is in the function that handles the response:

responseHandler.onResult = function( results: Object ):Void { //when results are back, populate the cfgrid contactList.dataProvider = results; }

Note: If you want the dataProvider to be an array (like it is when you load the grid normally), use: contactList.dataProvider = results.items; This will make it work if you are using our "Filtering as you type" code.

The number of records returned can be found at results.length. You could notify the user that no records were found.

responseHandler.onResult = function( results: Object ):Void { //when results are back, populate the cfgrid contactList.dataProvider = results; if (!results.length){ alert('No records found'); } }

The complete code:

//create connection var connection:mx.remoting.Connection = mx.remoting.NetServices.createGatewayConnection( "http://www.example.com/flashservices/gateway/"); //declare service var myService:mx.remoting.NetServiceProxy; var responseHandler = {}; //put the controls in scope to avoid calling _root var contactList = contactList; responseHandler.onResult = function( results: Object ):Void { //when results are back, populate the cfgrid contactList.dataProvider = results; } //function that receives any error that may have occurred during the call responseHandler.onStatus = function( stat: Object ):Void { //if there is any error, show an alert alert("Error while calling cfc:" + stat.description); } //get service myService = connection.getService("blog.examples.flashRemotingResponder", responseHandler ); //make call myService.getMembers();

The form only contains a cfgrid and a button that triggers the call.

A live example
Download the source