`
xmy20051643
  • 浏览: 39692 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

EXTJS 带文字和图标的action column

 
阅读更多

EXTJS 5的ACTION COLUMN好像没有文字的,所以自已改了一小点原来的代码。湊和起用吧,只能说。

 

/**
 * 带文字和图标的action column
 *
 *
 * @author <a href='mailto:xiaomingyang@aksl.com.cn'>xiaomingyang</a> 2016-01-19,17:08
 * @version v0.1
 */
Ext.define('Ext.grid.column.ActionText', {
    extend: 'Ext.grid.column.Column',
    alias: [
        'widget.actionTextcolumn'
    ],
    xtype : 'actionTextColumn',
    alternateClassName: 'Ext.grid.ActionTextColumn',
    stopSelection: true,
    actionIdRe: new RegExp(Ext.baseCSSPrefix + 'action-col-(\\d+)'),
    altText: '',
    menuText: '<i>操作</i>',
    sortable: false,
    innerCls: Ext.baseCSSPrefix + 'grid-cell-inner-actiontext-col',
    actionIconCls: Ext.baseCSSPrefix + 'action-col-icon',
    constructor: function(config) {
        var me = this,
            cfg = Ext.apply({}, config),

            items = cfg.items || me.items || [
                    me
                ],
            hasGetClass, i, len;
        me.origRenderer = cfg.renderer || me.renderer;
        me.origScope = cfg.scope || me.scope;
        me.renderer = me.scope = cfg.renderer = cfg.scope = null;

        cfg.items = null;
        me.callParent([
            cfg
        ]);

        me.items = items;
        for (i = 0 , len = items.length; i < len; ++i) {
            if (items[i].getClass) {
                hasGetClass = true;
                break;
            }
        }
        if (me.origRenderer || hasGetClass) {
            me.hasCustomRenderer = true;
        }
    },

    initComponent: function() {
        var me = this;
        me.callParent();
        if (me.sortable && !me.dataIndex) {
            me.sortable = false;
        }
    },

    defaultRenderer: function(v, cellValues, record, rowIdx, colIdx, store, view) {
        var me = this,
            prefix = Ext.baseCSSPrefix,
            scope = me.origScope || me,
            items = me.items,
            len = items.length,
            i = 0,
            j = 0,
            item, ret, disabled, tooltip;

        ret = Ext.isFunction(me.origRenderer) ? me.origRenderer.apply(scope, arguments) || '' : '';
        cellValues.tdCls += ' ' + Ext.baseCSSPrefix + 'action-col-cell';
        for (; i < len; i++) {
            item = items[i];
            disabled = item.disabled || (item.isDisabled ? item.isDisabled.call(item.scope || scope, view, rowIdx, colIdx, item, record) : false);
            tooltip = disabled ? null : (item.tooltip || (item.getTip ? item.getTip.apply(item.scope || scope, arguments) : null));

            if (!item.hasActionConfiguration) {

                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;
            }
            //ret += '<img role="button" alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) + '" class="' + me.actionIconCls + ' ' + prefix + 'action-col-' + String(i) + ' ' + (disabled ? prefix + 'item-disabled' : ' ') + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope || scope, arguments) : (item.iconCls || me.iconCls || '')) + '"' + (tooltip ? ' data-qtip="' + tooltip + '"' : '') + ' />';
            var spacesStr = '';
            if (item.spaces) {
                for (var si = 0; si < item.spaces; si++) {
                    spacesStr += '&nbsp';
                }
            }
            var iconStr =  '<div style="float:left;"><a href="#" class="x-action-col-' + String(j)  + '"><img role="button" alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) + '" class="' + me.actionIconCls + ' ' + prefix + 'action-col-' + String(i) + ' ' + (disabled ? prefix + 'item-disabled' : ' ') + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope || scope, arguments) : (item.iconCls || me.iconCls || '')) + '"' + (tooltip ? ' data-qtip="' + tooltip + '"' : '') + ' />' + item.showText + '</a>' + spacesStr + '</div>';
            ret += iconStr;
            j++;
        }
        return ret;
    },

    updater: function(cell, value, record, view, dataSource) {
        var cellValues = {};
        cell.firstChild.innerHTML = this.defaultRenderer(value, cellValues, record, null, null, dataSource, view);
        Ext.fly(cell).addCls(cellValues.tdCls);
    },

    enableAction: 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 = false;
        me.up('tablepanel').el.select('.' + Ext.baseCSSPrefix + 'action-col-' + index).removeCls(me.disabledCls);
        if (!silent) {
            me.fireEvent('enable', me);
        }
    },

    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);
        }
    },
    beforeDestroy: function() {


        this.renderer = this.items = null;
        return this.callParent(arguments);
    },

    processEvent: function(type, view, cell, recordIndex, cellIndex, e, record, row) {
        var me = this,
            target = e.getTarget(),
            key = type === 'keydown' && e.getKey(),
            match, item, disabled;
        if (key && !Ext.fly(target).findParent(view.getCellSelector())) {
            target = Ext.fly(cell).down('.' + Ext.baseCSSPrefix + 'action-col-icon', true);
        }
        if (target && (match = target.className.match(me.actionIdRe))) {
            item = me.items[parseInt(match[1], 10)];
            disabled = item.disabled || (item.isDisabled ? item.isDisabled.call(item.scope || me.origScope || me, view, recordIndex, cellIndex, item, record) : false);
            if (item && !disabled) {

                if (type === 'mousedown') {
                    if (item.stopSelection) {
                        e.preventDefault();
                    }
                    return false;
                }
                if (type === 'click' || (key === e.ENTER || key === e.SPACE)) {
                    Ext.callback(item.handler || me.handler, item.scope || me.origScope, [
                        view,
                        recordIndex,
                        cellIndex,
                        item,
                        e,
                        record,
                        row
                    ], undefined, me);


                    if (item.stopSelection !== false) {
                        return false;
                    }
                }
            }
        }
        return me.callParent(arguments);
    },
    cascade: function(fn, scope) {
        fn.call(scope || this, this);
    },

    getRefItems: function() {
        return [];
    },
    privates: {
        getFocusables: function() {


            return [];
        }
    }
});

 用例代码:

 

{
                xtype:'actionTextColumn',
                text : '操作',
                flex : 2,
                items: [{
                    iconCls : 'ext-grid-column-actionColumn-iconEdit',
                    showText : '修改',
                    tooltip : '修改角色',
                    spaces : 3,
                    handler: function(grid, rowIndex, colIndex, item,  e, record) {
                        var rec = grid.getStore().getAt(rowIndex);
                        _this._editRoleItem(rec);
                    }
                }, {
                    iconCls : 'ext-grid-column-actionColumn-iconView',
                    showText : '查看',
                    tooltip : '查看角色',
                    spaces : 3,
                    handler: function(grid, rowIndex, colIndex, item,  e, record) {
                        var rec = grid.getStore().getAt(rowIndex);
                        _this._viewRoleItem(rec);
                    }
                }, {
                    iconCls : 'ext-grid-column-actionColumn-iconDelete',
                    showText : '删除',
                    tooltip : '删除角色',
                    handler: function(grid, rowIndex, colIndex, item,  e, record) {
                        var rec = grid.getStore().getAt(rowIndex);
                        _this._deleteRoleItem(rec);
                    }
                }]
            }

 

 

 

  • 大小: 21.5 KB
分享到:
评论

相关推荐

    extjs图标大全extjs图标大全extjs图标大全extjs图标大全

    ExtJS图标大全是一个集合了多种图标的资源库,特别适合用于Web开发,尤其是使用ExtJS框架构建用户界面时。ExtJS是一款强大的JavaScript UI框架,它提供了丰富的组件和工具,帮助开发者构建功能丰富的、响应式的Web...

    包含各种类型的extjs小图标,Extjs4小图标

    在标题和描述中提到的“Extjs4小图标”指的是ExtJS 4版本中使用的一系列图形图标,这些图标用于增强应用程序的视觉效果,提供用户友好的操作指示。 1. **图标分类**: - 图标通常分为不同的类别,如操作图标(比如...

    extjs 2000个 icon 图标素材

    在ExtJS中,图标(icon)是用于增强UI视觉效果和用户体验的重要元素。这些图标通常用在按钮、菜单项、工具栏等组件上,以直观地表示功能或操作。"extjs 2000个 icon 图标素材" 提供了大量图标资源,适用于各种 ExtJS...

    extjs小图标(项目小图标大全)

    ExtJS的图标库通常会包含多种主题,如经典(Classic)、灰度(Gray)和现代(Neptune),以匹配不同风格的UI。开发者可以根据项目的视觉规范选择合适的主题,并通过设置全局样式来应用。 此外,图标可能还会分为几...

    EXTJS 项目图标

    3. Font图标:EXTJS可以配合字体图标库,如Font Awesome或Glyphicons,通过字体中的特殊字符来显示图标。 在实际项目中,开发者可以根据需求选择不同的图标使用方式。例如,在创建一个按钮时,可以这样设置图标: `...

    extjs图标大全

    ExtJS图标大全是一个集合了大量图标资源的库,专门用于ExtJS框架的UI设计和开发。这个压缩包包含了5000个不同的图标,旨在为开发者提供丰富的选择,以实现功能性和美观性的完美结合。ExtJS是一个强大的JavaScript UI...

    easyui,extjs图标icon图标大全

    "easyui"和"extjs"是两种广泛使用的JavaScript框架,主要用于构建用户界面,特别是企业级应用。这两种框架都提供了丰富的组件和样式,使得开发者能够快速创建功能齐全且美观的网页应用。在这些应用中,图标(icon)...

    extjs icon小图标

    这种方式将图标作为字体字符处理,允许通过改变字体大小和颜色来调整图标样式。 4. 图片集:图标也可能以PNG或JPEG等图像格式提供,适用于需要自定义颜色或透明度的情况。 在使用这些图标时,美工人员可以根据项目...

    Extjs 超级工具栏图标

    同时,合理使用图标集和图标映射策略也能有效优化资源加载。 9. **国际化支持**:EXTJS允许在不同的语言环境中使用相同的图标,通过调整工具提示或关联文字来适应不同的语言需求。 通过以上知识点,我们可以创建出...

    extjs图标和图标样式css

    在EXTJS框架中,图标和图标样式是UI设计的重要组成部分,它们可以显著提升用户界面的美观度和可操作性。EXTJS图标通常与按钮、工具条、菜单项等组件关联,用于表示各种功能或操作。在EXTJS中,图标有两种主要形式:...

    extjs easyui小图标

    ExtJS图标系统允许开发者为按钮、菜单项和其他UI元素添加视觉效果,增强其可识别性和美观性。这些图标通常通过CSS类名引用,可以是矢量图形,以确保在不同分辨率下都能清晰显示。 EasyUI则是一个基于jQuery的轻量级...

    extjs bug 图标大全

    它提供了丰富的组件库,包括表格、表单、树形视图、图表等,以及一套完整的主题和图标集。"extjs bug 图标大全" 指的是在ExtJS框架中与错误或问题相关的图标集合。这些图标通常用于表示程序中的错误状态、警告信息...

    ExtJs实用图标大全

    "ExtJs实用图标大全"包含了近千个专为ExtJs设计的小图标,尺寸为16x16像素,这种小尺寸的图标设计旨在确保在不同分辨率和屏幕尺寸下都能清晰可见。这些图标涵盖了各种常见功能和操作,如编辑、保存、删除、刷新、...

    ExtJs Icon 小图标集(1700+),附CSS生成实用小工具

    "ExtJs Icon 小图标集(1700+),附CSS生成实用小工具"是一个针对ExtJS开发者的资源包,它包含超过1700个图标,并配备了一个CSS生成工具,方便开发者快速集成和管理这些图标。 这个图标集适用于ExtJS 4.x版本,意味...

    5000个extjs小图标,真的非常的全面

    标题提到的"5000个ExtJS小图标"是一份包含大量图标资源的集合,这些图标可能用于增强ExtJS应用的界面美观度和用户体验。 在ExtJS中,图标通常被用作按钮、菜单项或其他UI元素的视觉表示。这些图标可以是基于字体的...

    extjs小图标大全小图标

    "extjs小图标大全小图标"这个资源集合提供了一系列用于ExtJS应用的图标,方便开发者在设计UI时选择和使用。 在ExtJS中,图标通常通过CSS类或者使用SVG图像来实现。这些图标可以是简单的图形,也可以是代表特定操作...

    5000个extjs小图标

    ExtJS是一款功能强大的JavaScript框架,主要用于...综上所述,"5000个extjs小图标"这个资源为ExtJS开发者提供了丰富的图标选择,可以满足多种设计需求,同时通过合理的管理和使用,可以提升Web应用的用户体验和专业性。

    5000个extjs小图标.zip

    在提供的压缩包"5000个extjs小图标.zip"中,包含了大量图标资源,这些图标可能是为ExtJS应用程序设计的,用于增强界面的用户体验和视觉效果。 首先,我们要理解ExtJS中的图标是如何使用的。在ExtJS中,图标通常用于...

    5000个常用到extjs小图标

    "5000个常用到EXTJS小图标"的资源集合,是一个专门针对EXTJS开发者的图标库,包含了大量的图标资源,旨在帮助开发者快速找到适合的图标来装饰和功能化他们的EXTJS应用程序。这些图标可能是SVG或PNG格式,具有高清晰...

Global site tag (gtag.js) - Google Analytics