PDA

View Full Version : ActionColumn / first parameter of getClass function always empty



jeremie
1 Dec 2010, 7:31 AM
Hi,

I think I found a bug :

When using ActionColumn, the first parameter of the function getClass is always empty, and never contains the value of column's field.



columns: [{
xtype: 'actioncolumn',
dataIndex: 'myField',
width: 50,
items: [{
getClass: function(v, medaData, record) {
// v => (an empty string)
return 'myClass'
},
handler: function(grid, rowIndex, colIndex) {

}
}]
}]
I think it comes from the definition of the function renderer in ActionColumn's constructor, where the variable v is overriden.

This fixes the bug :



// Original version
me.renderer = function(v, meta) {

v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : '';

meta.css += ' x-action-col-cell';
for (i = 0; i < l; i++) {
item = items[i];
v += '<img alt="' + me.altText + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
'" class="x-action-col-icon x-action-col-' + String(i) + ' ' + (item.iconCls || '') +
' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||this.scope||this, arguments) : '') + '"' +
((item.tooltip) ? ' ext:qtip="' + item.tooltip + '"' : '') + ' />';
}
return v;
};

// New version
me.renderer = function(value, meta) {

v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : '';

meta.css += ' x-action-col-cell';
for (i = 0; i < l; i++) {
item = items[i];
v += '<img alt="' + me.altText + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
'" class="x-action-col-icon x-action-col-' + String(i) + ' ' + (item.iconCls || '') +
' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||this.scope||this, arguments) : '') + '"' +
((item.tooltip) ? ' ext:qtip="' + item.tooltip + '"' : '') + ' />';
}
return v;
};

jeremie
3 Dec 2010, 12:14 AM
Sorry I'm in the wrong topic, I wanted to post in "Ext: Bugs".

Condor
3 Dec 2010, 3:57 AM
Changing the value of 'v' has no influence on the content of 'arguments'.

This means that your fix has absolutely NO effect!

Are you sure 'myField' actually exists in your store record?

jeremie
3 Dec 2010, 5:50 AM
Thanks for reply.

My fix works properly for me, and i'm sure "myField" exists in my store.

If i do this :



me.renderer = function(v, meta) {

v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : 'test';

meta.css += ' x-action-col-cell';
for (i = 0; i < l; i++) {
item = items[i];
v += '<img alt="' + me.altText + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
'" class="x-action-col-icon x-action-col-' + String(i) + ' ' + (item.iconCls || '') +
' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||this.scope||this, arguments) : '') + '"' +
((item.tooltip) ? ' ext:qtip="' + item.tooltip + '"' : '') + ' />';
}
return v;
};
Here is the result :



columns: [{
xtype: 'actioncolumn',
dataIndex: 'myField',
width: 50,
items: [{
getClass: function(v, medaData, record) {
// v equals 'test'
return 'myClass'
},
handler: function(grid, rowIndex, colIndex) {

}
}]
}]
So, i think reusing the same variable name 'v', has an impact in the content of 'arguments'.

Condor
4 Dec 2010, 12:39 AM
I stand corrected. Didn't know that you could modify arguments by modifying parameters, e.g.


function fn(param){
param = 'world';
return arguments[0];
}
fn('hello') == 'world'

(really counter intuitive!)

jeremie
6 Dec 2010, 12:28 AM
Ok, so the subject is closed, could someone move the post to Ext:Bugs ?

huguogang
15 Jan 2013, 11:34 AM
This is still a bug in version 4.1.1a, as of 1/15/2013.