PDA

View Full Version : Passing to function()



dhanek
29 Oct 2007, 11:23 AM
In the below code How can I pass the window instance to the function, when I double click the grid.


dblClick = function (g,r,e,window){
// sample code
}

Grid.getGrid().on("rowdblclick", dblClick(SampleWindow));

Thanks in advance,
Dhanek.

jay@moduscreate.com
29 Oct 2007, 12:01 PM
The easiest way is to make sure that the var window is declared before the grid is.

So

var win = mywindow

var grid = my grid
grid.on('rowdblclick', function() {
win.show();
});

dhanek
29 Oct 2007, 12:15 PM
Thank you for your reply.

But wht i am trying to do is...

When you doubleclick the row in the grid

1) It will call the function dblClick..

Grid.getGrid().on("rowdblclick", dblClick(sampleWindow));

2) for that function i want to pass the window insatance...

function dblClick(window){
window.getForm().setAction('edit');
row = g.dataSource.getAt(r);
alert('asdf');
window.setForm(row);
window.show(msg_id);
};

And also i declare my window var sampleWindow = window(); at the top.


But it is giving the error

g is not defined(It has default parameters g,r,e))

It is fine if u just give

Grid.getGrid().on("rowdblclick", dblClick);

I mean no error..but i want to pass the window to the function..

Thank you,
Dhanek.

jay@moduscreate.com
29 Oct 2007, 12:31 PM
you don't need to do all of that. if the window var is global in scope to the grid, you're golden. you don't have to pass the window object to the dblclick funciton.

the first parameter passed to the dblclick function is the actual grid (or g as you call it).
second is the row index,
third is the event object


rowdblclick
public event rowdblclick
Fires when a row is double clicked
Subscribers will be called with the following parameters:

* this : Grid
* rowIndex : Number
* e : Ext.EventObject

This event is defined by Grid.