PDA

View Full Version : Action Column disabling for row (after render)



aronsky
11 Feb 2014, 4:56 AM
I found some interesting behavior of action column. My problem was to disable action for row if property in model equals with something. So, the correct way is to use "isDisabled" property of action column:


var actionColumn = Ext.create('Ext.grid.column.Action', {
header: 'Cancel',
xtype:'actioncolumn',
iconCls: 'icon-ban-circle',
items: [{
isDisabled: function(v, rowIndex, colIndex, item, rec) {
return (rec.get('status') == 'cancelled');
},
handler: this.cancelOrderHandler
}]
});
Ok, this works when grid view is rendered. But when i modify status


order.set('status', 'cancelled');

the action column doesn't changes to disabled (the function is called, but nothing changes).

Somewhere i found, that this property can change 'disabled' property only on render. So, i tried to use method disableAction(). From sources i found that it changes css class and doesn't call disable() method if 'slent' (second param) is set to true - it's exactly what we need. But i can't be able to use it: if the index (first param) was greater than 0, it crashes on

me.items[index].disabled = true;, because it have only one item. If i call this method with index=0 it disables the whole row. So, looks like i don't understand how to call this method.

And one interesting thing, which i found: i wanted to use getClass property for setting 'disabled' manually and just for experiment i modified my code:

var actionColumn = Ext.create('Ext.grid.column.Action', {
header: 'Cancel',
xtype:'actioncolumn',
items: [{
isDisabled: function(v, rowIndex, colIndex, item, rec) {
return (rec.get('status') == 'cancelled');
},
getClass: function(v, meta, rec) {
return 'icon-ban-circle';
},
handler: this.cancelOrderHandler
}]
});

And now it applies the disabled class when order.set() is called.
I really don't know if this is a bug or feature, but looks like if i add getClass property, it changes the element according to isDisabled conditions.

My ExtJS version is 4.2.

Zinnia
12 Feb 2014, 12:20 AM
Hi Aron,

Have tested the below code, it is working fine at my end. After setting the new value just refresh the grid it will work.

i.e. grid.getView(). refresh();

aronsky
12 Feb 2014, 1:03 AM
Hi Aron,

Have tested the below code, it is working fine at my end. After setting the new value just refresh the grid it will work.

i.e. grid.getView(). refresh();
Thanks for your reply. Yes, i understand, that adding getClass property will cause grid refreshing and this is the reason why code from my last example works. But questions were others:
1. Why adding isDisabled property does not causes grid refreshing? I do not see any advantages of such behavior.
2. How to work with disableAction() and what is reason of this method?

cberinde
11 Dec 2015, 6:04 AM
In ExtJs 6 the isDisabled works as expected :
- is called whenever a row is re-rendered