Skip to main content
Inspiring
May 12, 2014
Question

How to capture the reconfigure event on ajax grid?

  • May 12, 2014
  • 1 reply
  • 424 views

In CF9 i have a cfgrid bound to a hidden field and a cfc query component.

Then i have a select box where the onChange() event triggers a js function which updates the hidden field with the select value and triggers the cfc, populating the grid with new data.

In this js function, i'm trying to add an event that would trigger a chunk of code when the grid is refreshed, like:

function myFunc(val) {

  document.getElementById('myHiddenField').value=val;

ColdFusion.Grid.refresh('myGrid',true);

  var grid = ColdFusion.Grid.getGridObject('myGrid');

  grid.addEvents('reconfigure');

  grid.on('reconfigure',function(){

     alert("Grid changed!");

  });

}

I don't get an error but the function never executes, don't get the alert. If i change the event to something that happens AFTER the grid gets refreshed, like grid.addEvents('click') it works fine. What am I missing?

Thanks

This topic has been closed for replies.

1 reply

ionAuthor
Inspiring
May 12, 2014

I think i've solved it, it's interesting. Looks like ColdFusion.Grid.refresh('myGrid',true); starts executing asynchronously, the rest of the function keeps going and it can execute BEFORE the grid.refresh finishes.

I moved my triggered code to a different function and added a delay, like:

function myFunc(val) {

  document.getElementById('myHiddenField').value=val;

  ColdFusion.Grid.refresh('myGrid',true);

  myVar = setInterval(myOtherFunc,1000);

}

function myOtherFunc() {

  var grid = ColdFusion.Grid.getGridObject('myGrid');

  // add whatever code you need

}