views:

1436

answers:

3

I have an ExtJS grid that has a button set up in it. The button triggers a function that's defined into other JS file that's included in the grid page. The function triggers ok but in that function I want to get the columns count like this:

grid.getColumnModel().getColumnCount()

The problem is that I get an error like: grid.getColumnModel is not a function.

In PHP I would make a "global $ext" and then access that function. How can I do this in Ext ? How can I access the grid from other file ? What needs to be defined ?

Thank you.

+1  A: 

How did you define the grid object? Did you do it like this:

var grid = new Ext.grid.GridPanel(...);

If so, the grid object is not in global scope. Remove the "var" and see if it helps.

Tommi
Damn, I thought this is something to do with global accessing the Ext objects or something.
Manny Calavera
+1  A: 

This looks like a scope issue. See variable scope in JavaScript.

Basically, you can do:

my_global_grid = ... // accessible in the current ~global~ context (document, window)
var my_local_grid = ... // accessible only in the function
window.my_window_global_grid = ... // accessible in the same window
streetpc
Thanks. Tommi answered first, sorry.
Manny Calavera
no problem :)
streetpc
A: 

You might also pass the grid object into your function as an argument:

function myFunction(arg1,arg2,grid){
   ...
    var count = grid.getColumnModel().getColumnCount();
   ...
}
Steve -Cutter- Blades