Font-Awesome ExtJS ActionColumn

lcg*_*ida 9 css extjs ruby-on-rails font-awesome

我在我的应用程序中使用FontAwesome和ExtJS.

当我这样做时,所有其他按钮工作正常,字体很棒:

 iconCls: 'fa fa-edit'
Run Code Online (Sandbox Code Playgroud)

但是,当在actioncolumn(允许您将按钮放在网格上的组件)中使用相同的配置时,图标就不会出现.

有谁知道为什么?

编辑

在尝试了@qdev之后回答:我只是看到了一个?#f040; 呈现的文字(蓝色).

为操作列按钮生成的HTML:

<span data-qtip="Edita registro" style="font-family:FontAwesome" class="x-action-col-icon x-action-col-glyph x-action-col-2   " title="" role="button">?xf040;</span>
Run Code Online (Sandbox Code Playgroud)

CSS(取自萤火虫检查员):

element.style {
    font-family: FontAwesome;
}
*, *:before, *:after {
    box-sizing: border-box;
}
*, *:before, *:after {
    box-sizing: border-box;
}
.x-action-col-icon {
    cursor: pointer;
    height: 16px;
    width: 16px;
}
.x-border-box, .x-border-box * {
    box-sizing: border-box;
}
.x-action-col-glyph {
    color: #9bc8e9;
    font-size: 16px;
    line-height: 16px;
    width: 20px;
}
*, *:before, *:after {
    box-sizing: border-box;
}
element.style {
    text-align: center;
}
.x-grid-cell-inner-action-col {
    font-size: 0;
    line-height: 0;
}
.x-grid-cell-inner {
    white-space: nowrap;
}
.x-grid-cell {
    font: 11px/13px tahoma,arial,verdana,sans-serif;
}
.x-unselectable {
    cursor: default;
}
.x-grid-table {
    border-collapse: separate;
}
.x-unselectable {
    cursor: default;
}
.x-panel-body-default {
    color: black;
    font-size: 12px;
}
.x-panel-body-default {
    color: black;
    font-size: 12px;
}
.x-panel-body-default {
    color: black;
    font-size: 12px;
}
.x-panel-body-default {
    color: black;
    font-size: 12px;
}
.x-panel-body-default {
    color: black;
    font-size: 12px;
}
.x-panel-body-default {
    color: black;
    font-size: 12px;
}
.x-body {
    color: black;
    font-family: tahoma,arial,verdana,sans-serif;
    font-size: 12px;
}
body {
    color: #222222;
    cursor: default;
    font-family: "Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif;
    font-style: normal;
    font-weight: normal;
    line-height: 150%;
}
html, body {
    font-size: 100%;
}
html, body {
    font-size: 100%;
}
Run Code Online (Sandbox Code Playgroud)

qde*_*dev 21

这是因为网格操作列图标呈现为IMG接受图标(路径)作为选项的标记.

为了能够使用它,你必须覆盖Ext.grid.column.Action *defaultRenderer*方法,以支持图标旁边的字形配置选项(在你的代码上你可以决定你使用图标imgglyph任何视图上的每个动作).

工作(在ExtJS 5.0.1上测试,但我认为它也适用于ExtJS 4)这个覆盖的代码:

Ext.define('MyApp.overrides.grid.column.Action', {
    override: 'Ext.grid.column.Action',

    // overridden to implement
    defaultRenderer: function(v, meta, record, rowIdx, colIdx, store, view){
        var me = this,
            prefix = Ext.baseCSSPrefix,
            scope = me.origScope || me,
            items = me.items,
            len = items.length,
            i = 0,
            item, ret, disabled, tooltip, glyph, glyphParts, glyphFontFamily;

        // Allow a configured renderer to create initial value (And set the other values in the "metadata" argument!)
        // Assign a new variable here, since if we modify "v" it will also modify the arguments collection, meaning
        // we will pass an incorrect value to getClass/getTip
        ret = Ext.isFunction(me.origRenderer) ? me.origRenderer.apply(scope, arguments) || '' : '';

        meta.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));
            glyph = item.glyph;

            // 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;
            }

            if (glyph) {
                if (typeof glyph === 'string') {
                    glyphParts = glyph.split('@');
                    glyph = glyphParts[0];
                    glyphFontFamily = glyphParts[1];
                } else {
                    glyphFontFamily = Ext._glyphFontFamily;
                }

                ret += '<span role="button" title="' + (item.altText || me.altText) + '" class="' + prefix + 'action-col-icon ' + prefix + 'action-col-glyph ' + prefix + 'action-col-' + String(i) + ' ' + (disabled ? prefix + 'item-disabled' : ' ') +
                    ' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope || scope, arguments) : (item.iconCls || me.iconCls || '')) + '"' +
                    ' style="font-family:' + glyphFontFamily + '"' +
                    (tooltip ? ' data-qtip="' + tooltip + '"' : '') + '>&#' + glyph + ';</span>';
            } else {
                ret += '<img role="button" alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
                    '" class="' + prefix + 'action-col-icon ' + 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 + '"' : '') + ' />';
            }
        }
        return ret;    
    }
}); 
Run Code Online (Sandbox Code Playgroud)

如果您不知道放置或加载它的位置,您可以在互联网上找到,但在sencha cmd生成的应用程序上,您只需将其放入appFolder/overrides/grid/column/Action.js并将自动加载框架.

然后你必须调整一些CSS(我在主视口的自定义CSS中添加).如果没有这个,你将看不到glyps,我想你会明白为什么看下面的代码:

.x-action-col-glyph {font-size:16px; line-height:16px; color:#9BC8E9; width:20px}
.x-action-col-glyph:hover{color:#3892D3}
Run Code Online (Sandbox Code Playgroud)

我还成功地做了另一个很好的技巧:默认情况下隐藏所有行的动作图标,并仅在悬停的行/记录上显示它们.

你可以选择在哪里使用它,只使用图标/字形的getClass配置函数,通过添加x-hidden-display(在较旧的ExtJS版本上可能是x-hide-display)类来实现你想要的视图:

{
  glyph: 0xf055,
  tooltip: 'Add',
  getClass: function(){return 'x-hidden-display'}
}
Run Code Online (Sandbox Code Playgroud)

...然后仅使用CSS显示悬停/选定行的所有图标:

.x-grid-item-over .x-hidden-display, .x-grid-item-selected .x-hidden-display{display:inline-block !important}
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助你 ;)