PDA

View Full Version : Dynamic Grid rowclick - extjs 3



Natkeeran
4 Nov 2009, 11:32 AM
Hello All:

I've implemented a dynamic grid (creating column modal and data store on the fly) using the code in this post: http://www.extjs.com/forum/showthread.php?t=3719

That code seems to be outdated, Thus, I modified

new Ext.grid.Grid(container, {piece into this:

grid1 = new Ext.grid.EditorGridPanel({You can see it here: http://pssnet.com/~devone/extjs3/DynamicReader2.html (http://pssnet.com/%7Edevone/extjs3/DynamicReader2.html)

The good thing is that it works. But, I need to enable select on this grid.

I defined a global grid variable (grid1), and bind an event on rowclick as below.


grid1.on('rowclick', function(grid1, rowIndex, e) {
alert ("test");
});It throws "grid1 is undefined" error.


I think this is because the grid is defined within here: ds.on('load', function() {.
Any variable is not defined outside that scope. Even if I assign to a global variable!??






Thanks.

uniring
4 Nov 2009, 12:00 PM
You're calling grid1.on() before grid1 is created because you're creating the grid in an asynchronous function.

Natkeeran
4 Nov 2009, 12:21 PM
How can I make it synchronous?

uniring
4 Nov 2009, 5:58 PM
You can't, you are doing an ajax (asynchronous) request to get the grid config so you can't create the grid before the request is complete.

Try to setup the event handler after you create the grid, inside the asynchronous function.

You need to understand how your code is executed over time, put some alerts to debug and see how it works, also FireBug or a similar debugger can be your friend with breakpoints.