How to call a javascript function when cfgrid finish loading data

1.5k Views Asked by At

I am using Coldfusion 9 cfgrid. I want to do things:

1) Call a javascript function when all data inside cfgrid finish loading.

2) Call a javascript function when we click on next page in pagination.

3

There are 3 best solutions below

0
On
var ds = mygrid.getDataSource()
ds.addListener('load', function() {

http://www.coldfusionjedi.com/index.cfm/2009/4/9/Ask-a-Jedi-Noticing-an-empty-CFGRID

0
On

1) use "onload" to specify a javascript function to call when the data has finished loading into the grid.

2) There is no parameter to specify a js function when data is reloaded, but you could get the id or the class of the 'next' button and bind your function to a click event on this element.

0
On

For your first question, you could do something like this

// function to fire when grid is finished loading 
getTotalRows = function() {
    var isGrid = ColdFusion.Grid.getGridObject('myGrid');
     var isData = isGrid.getStore();
     isData.addListener("load", function() {
         if(isData.totalLength == 0) {
           alert("No records found");
           return false;
         }
     });
}
ColdFusion.Event.registerOnLoad(getTotalRows,null,false,true);

The last line (CF.Event etc) triggers the function call when the grid is loaded.