-
26 Sep 2012 5:33 AM #1
ActionColumn Disabled property cannot be set in getClass method
ActionColumn Disabled property cannot be set in getClass method
REQUIRED INFORMATION
Ext version tested:- Ext 4.1.1
- FF
- Chrome
- html5
- It is not possible to disable an action column item in the getclass method.
Just create an action column and try to disable an item in the getClass method. Code listed below.
The result that was expected:
Disabled action item.
The result that occurs instead:
Enabled action item.
Test Case:
xtype:'actioncolumn',
width: 50,
menuDisabled: true,
sortable: false,
items: [{
icon: 'hmet/Content/resources/empty.png',
getClass : function(v, meta, rec) {
console.log('this.items[0].disabled = rec.data.leaf:' + rec.data.leaf);
this.items[0].disabled = rec.data.leaf;
return 'p-grid-action-add'; },
handler : function(view, rowIndex, colIndex, item, e) {
if (!item.disabled) {
this.fireEvent('itemclick', this, 'add', view, rowIndex, colIndex, item, e);
}
}
}
Possible fix:
Default Renderer method of action column class has to be changed, that the disabled property is not read before calling the method itself. Changed lines in bold.
Code:// Renderer closure iterates through items creating an <img> element for each and tagging with an identifying // class name x-action-col-{n} defaultRenderer: function(v, meta){ var me = this, prefix = Ext.baseCSSPrefix, scope = me.origScope || me, items = me.items, len = items.length, i = 0, item; // Allow a configured renderer to create initial value (And set the other values in the "metadata" argument!) v = Ext.isFunction(me.origRenderer) ? me.origRenderer.apply(scope, arguments) || '' : ''; meta.tdCls += ' ' + Ext.baseCSSPrefix + 'action-col-cell'; for (; i < len; i++) { item = items[i]; // Only process the item action setup once. if (!item.hasActionConfiguration) { // Apply our documented default to all items item.stopSelection = me.stopSelection; item.disable = Ext.Function.bind(me.disableAction, me, [i], 0); item.enable = Ext.Function.bind(me.enableAction, me, [i], 0); item.hasActionConfiguration = true; } v += '<img alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) + '" class="' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope || scope, arguments) : (item.iconCls || me.iconCls || '')) + ' ' + prefix + 'action-col-icon ' + prefix + 'action-col-' + String(i) + ' ' + (item.disabled ? prefix + 'item-disabled' : ' ') + '"' + ((item.tooltip) ? ' data-qtip="' + item.tooltip + '"' : '') + ' />'; } return v; },
-
26 Sep 2012 6:09 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
Have you tried to execute the disable() method instead of setting the disabled config?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
26 Sep 2012 11:46 AM #3
Hi mitch,
no I didn't try due to the disable method cannot be successful while initiating the rendering process. This was also my first thought but looking at the sources mean that this cannot work. The disable method expects the action columns to be rendered.(Have a look onto the sources, the addCls will certainly fail)
On the other hand it does not make sense to raise events initially. The bugfix is just correcting the wrong ordering of the information that is going to be part of the img that is build for the action column.
regards
hiro.
Code:disableAction: function(index, silent) { var me = this; if (!index) { index = 0; } else if (!Ext.isNumber(index)) { index = Ext.Array.indexOf(me.items, index); } me.items[index].disabled = true; me.up('tablepanel').el.select('.' + Ext.baseCSSPrefix + 'action-col-' + index).addCls(me.disabledCls); if (!silent) { me.fireEvent('disable', me); } },
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote