Beetlejuice
Beetlejuice

Reputation: 4425

getClass for actionColumn only in a few rows

I'm using the code below, to set the css class for an action column. But even if the result is null, some elements are inserted by extjs.

getClass: function(v, meta, data) {        
  if (data.myDate < new Date())
        return null;
  else
        return 'insert';
}

Generated html for return null:

<img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" 
class="x-action-col-icon x-action-col-1   null">

The major problem is that cursor is changed to a hand pointer when moving this "blank" space.

There is a way to not generate elements when no icon is to be shown?

Upvotes: 0

Views: 1947

Answers (1)

Krzysztof
Krzysztof

Reputation: 16150

I don't see any way to do it without extending action column. IMO easiest way is to provide custom renderer function. Example:

Ext.define('Ext.grid.column.MyAction', {
    extend: 'Ext.grid.column.Action',

    constructor: function(config) {
        var me = this, 
            cfg = Ext.apply({}, config),
            items = cfg.items || [me],
            l = items.length,
            i,
            item,
            cls;

        me.callParent(arguments);

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

            meta.tdCls += ' ' + Ext.baseCSSPrefix + 'action-col-cell';
            for (i = 0; i < l; i++) {
                item = items[i];
                item.disable = Ext.Function.bind(me.disableAction, me, [i]);
                item.enable = Ext.Function.bind(me.enableAction, me, [i]);

                cls = (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||me.scope||me, arguments) : (me.iconCls || ''));
                if (cls !== null) {
                    v += '<img alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
                        '" class="' + Ext.baseCSSPrefix + 'action-col-icon ' + Ext.baseCSSPrefix + 'action-col-' + String(i) + ' ' + (item.disabled ? Ext.baseCSSPrefix + 'item-disabled' : ' ') + (item.iconCls || '') +
                        ' ' + cls + '"' +
                        ((item.tooltip) ? ' data-qtip="' + item.tooltip + '"' : '') + ' />';
                }
            }
            return v;
        };
    }

});

Upvotes: 1

Related Questions