PDA

View Full Version : cellclick handler with additional parameter



Suresh Arumugam
12 Jul 2010, 6:57 AM
Hi,
I am new to ext js.
I need to call a javascript function when grid cell is clicked with cell data as one of the parameter value.

If I can use cellclick event handler like below,

grid.on('cellclick', handler);


function handler(grid, rowIndex, columnIndex, e) {
var record = grid.getStore().getAt(rowIndex); // Get the Record

var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name

var data = record.get(fieldName);
alert("data :"+data);
}

Is there any possiblity to include additional parameter to cellclick handler along with default parameters or
any other option to call a javascript function with my own parameters?

Note :- renderer : handler.createDelegate(this,{param:'value'}) does not work for my requirement.

Thank you,
Suresh Arumugam

Condor
12 Jul 2010, 7:25 AM
You mean something like:

handler.createDelegate(this, ['value'], 4)
with:

function handler(grid, rowIndex, columnIndex, e, param) {...}

tomcruz
12 Jul 2010, 7:35 AM
I think you were on the right track with the createDelegate solution...

It actually takes 3 parameters (according to the docs : http://www.sencha.com/deploy/dev/docs/?class=Function)
- Scope : the this object when you call the handler
- Args : An array with the arguments you want to override OR add
- appendArgs: can be a boolean or number, in your case you will want to set this as true so that the args array gets appended after the normal handler args. I don't see a case where you would want to override those.

Your code would look like

grid.on('cellclick', handler.createDelegate(this, ['a',{a: 'letterA',b: 'letterB'}], true);

This would invoke your handler with the usual parameters, plus two other parameters: the string 'a' and a complex object.

Suresh Arumugam
12 Jul 2010, 7:50 AM
You mean something like:

handler.createDelegate(this, ['value'], 4)
with:

function handler(grid, rowIndex, columnIndex, e, param) {...}


Hi,

Yes something like :
function handler(grid, rowIndex, columnIndex, e, param) {...}

tomcruz
12 Jul 2010, 7:51 AM
Ah my post got squeezed ! But Condor was more concise :)

In the createDelegate call, you can replace "4" with "true" so that the custom arguments get appended after the normal event handler ones, regardless of their number.

Condor
12 Jul 2010, 7:56 AM
I find it better to use a number instead of 'true', because some event handlers don't have a fixed number of parameters and some (like tree node events) have more (empty) parameters than are specified in the docs.

Suresh Arumugam
12 Jul 2010, 11:14 PM
Thanks for your replies.
I find the below code suitable for my design.
function handler(grid, rowIndex, columnIndex, e, param) {...}