ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: Robert on April 23, 2014, 01:45:12 am

Title: Call a function in a second grid
Post by: Robert on April 23, 2014, 01:45:12 am
I have 2 grids in separate <div>'s but in one php page.

Both grids are working perfectly HOWEVER, I would like to call a function in one of the grids from the other one (and pass in a var). Because they are wrapped in self executing functions, I cannot access the internal function of the opposite grid.

Is it possible to call an internal function of one grid from another grid?

Thanks in advance!
Title: Re: Call a function in a second grid
Post by: Robert on April 23, 2014, 02:18:07 am
After miles of searching before asking the question here ... I didn't realize how close I was to the answer. My apologies. I found an example that allows this to happen and it works beautifully.

 (function($) {

     var namespace;
         namespace = {
                     something : function() {
                                             alert('hello there!');
                                            },
                      bodyInfo : function() {
                                             alert($('body').attr('id'));
                                            }
                     };
         window.ns = namespace;
    })(this.jQuery);

   $(function() {
              ns.something();
              ns.bodyInfo();
   });
Title: Re: Call a function in a second grid
Post by: paramvir on April 23, 2014, 01:50:38 pm
Common solution to this is:

If you want to call API of a grid for which you don't have its instance variable, you can always get reference to it using the selector.

$(function(){
  //grid A constructed in this function.
  var obj = {....};
  var $gridA = $("#A").pqGrid( obj );
});

$(function(){
  var $gridA = $("#A");
  //call methods
  $gridA.pqGrid( 'some method' );
});
Title: Re: Call a function in a second grid
Post by: Robert on April 25, 2014, 03:49:49 am
Fantastic suggestion! THANK YOU!!! I will work with this and see if it solves what appears to be a scope issue I am having. Thank you again.
Title: Re: Call a function in a second grid
Post by: Robert on April 25, 2014, 06:04:06 am
This seems so simple but I am having issues getting this to work. Is there and example I can see where this is implemented?
Title: Re: Call a function in a second grid
Post by: Robert on April 25, 2014, 06:28:51 am
OH MY ... I got it to work!!! You are a life saver!!!