Font-Awesome ExtJS ActionColumn

I am using FontAwesome with ExtJS in my application.

All other buttons work fine with the font when I do this:

iconCls: 'fa fa-edit' 

For example.

But when using the same configuration in the action column (Component, which allows you to pu buttons on the Grid), the icon simply does not appear.

Does anyone have an idea why?

EDIT

After trying to answer @qdev: am I just seeing? # f040; text is displayed (in blue).

The generated HTML for the action column button:

 <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> 

CSS (taken from firebuh inspector):

 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%; } 
+7
css ruby-on-rails extjs font-awesome
source share
5 answers

This is because the grid table column icons are displayed as IMG tags that take a parameter (path) as an option.

To use this, you must override the Ext.grid.column.Action *defaultRenderer* method to support the glyph configuration option next to the icon (and in your code you can decide that you go with the IMG or glyph for each action in any view )

Work (tested on ExtJS 5.0.1, but I think it works with ExtJS 4 as well) for this override:

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

If you don’t know where to put it or download it, you can find it on the Internet, but in the sencha application created by cmd, you just put it in appFolder/overrides/grid/column/Action.js and load the framework automatically.

Then you need to adjust some CSS a bit (I added to my custom CSS for the main viewport). Without this, you will not see glyphs, I suppose you will understand why you look at the code below:

 .x-action-col-glyph {font-size:16px; line-height:16px; color:#9BC8E9; width:20px} .x-action-col-glyph:hover{color:#3892D3} 

I also managed to do another good trick: hide the default action icons for all lines and show them only on line / record hang.

You can choose where to use it only on the views that you want to use using the getClass icon / glyph configuration function by adding x-hidden-display (for an older version of ExtJS it might be x-hide-display ) with the following class:

 { glyph: 0xf055, tooltip: 'Add', getClass: function(){return 'x-hidden-display'} } 

... and then show all the icons for the hover / selected row using only CSS:

 .x-grid-item-over .x-hidden-display, .x-grid-item-selected .x-hidden-display{display:inline-block !important} 

Hope this helps you;)

+18
source share

I add getGlyph (similar to getClass for icons) to qdev . This is a very simple solution, but works great.

Is there just 3 lines, qdev adds the solution:

  if(Ext.isFunction(item.getGlyph)){ glyph = item.getGlyph.apply(item.scope || scope, arguments); }else{ glyph = item.glyph; } 

Full redefinition code:

 Ext.define('corporateCms.overrides.grid.column.Action', { override: 'Ext.grid.column.Action', // overridden to implement 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, 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) || '' : ''; 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(Ext.isFunction(item.getGlyph)){ glyph = item.getGlyph.apply(item.scope || scope, arguments); }else{ 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="' + 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 + '"' : '') + ' />'; } } return ret; } }); 

You can use it as simple as:

  getGlyph: function(v, meta, rec) { if (rec.get('access')) { return ' xf067@FontAwesome '; } else { return ' xf068@FontAwesome '; } }, 

Hope this helps you;)

+2
source share

You can simply return the fa fa-edit class from the actioncolumn getClass element as follows:

 { xtype: 'actioncolumn', items: [{ getClass: function () { return 'x-fa fa-users'; } }] } 
+2
source share

I recently created this new application that will help you prepare custom icons that you can assign iconCls . It generates the _icons.scss file for your Sencha applications. I only tested it with Sencha Touch, but I think it should work with ExtJS as well. README explains the steps for creating icons on the Ico Moon website and using the tool to convert Ico Moon project files to SCSS for use in Sencha. It has also been tested with Sencha Architect Touch designs.

If you use it for ExtJS, tell me if it works. Thanks.

+1
source share

Overrides don't seem to work if you're in 4.0 - 4.1. I took the path of least resistance and simply made the icons in png format via http://fa2png.io/ , then determined the assigned class to the background image URL in css.

0
source share

All Articles