I'm using angular-fontawesome and datatables and I want to create a button in the table, but instead of text I want to place an icon using fontawesome. I have the following code:
this.dtOptions = {
//...
buttons: [
//...
{
extend: 'pdf',
text: '<fa-icon [icon]="faDownload"></fa-icon>'
}
]
};
I know that I will not load the component of the icon in this way, but is there a way to do it without having to use the fontawesome css?
To display Table font awesome icon, add predefined class name i.e., fa-table (with prefix fa- ) to the i tag. And we need to add corresponding font awesome icon style for the Table icon. Table icon has 1 icon style i.e.,solid. We need to append icon style class fas .
In bootstrap you can implement buttons using combination of <a> and <i> . Similarly , in font-awesome buttons with icons can be implemented using a combination of <button> and <span> . Wadih M. For most buttons you'll want the icons to be fixed-width so all of your icon-buttons appear the same size.
You can upload as many icons as your plan allows (in one or across many Kits). Uploaded icons can have the same name as official Font Awesome icons (the unique prefix will set them apart)
As long as you have fontawesome loaded you can just manipulate the className
property. I will recommend you to reset the default button layout setup through the dom
property as well. As other points out, do not mix angular (+2) directives with that part of the code. It will probably not work (I am into angular1, but its the same deal) and really not necessary anyway. Here is an example :
buttons: {
//reset class and change the rendered tag
//from <button> to <i>
dom: {
button: {
tag: 'i',
className: ''
}
},
//since we now have completely unstyled icons add
//some space between them trough a .custom-btn class
buttons: [
{
titleAttr: 'Download as PDF',
extend: 'pdfHtml5',
className: 'custom-btn fa fa-file-pdf-o',
text: ''
},
{
titleAttr: 'Download as Excel',
extend: 'excelHtml5',
className: 'custom-btn fa fa-file-excel-o',
text: ''
},
{
titleAttr: 'Download as CSV',
extend: 'csvHtml5',
className: 'custom-btn fa fa-file-text-o',
text: ''
},
{
titleAttr: 'Print',
extend: 'print',
className: 'custom-btn fa fa-print',
text: ''
}
]
}
.custom-btn {
cursor: pointer;
margin-right: 5px;
}
https://jsfiddle.net/r47ao4h3/
I do not have a working plunkr using DT and Angular2 at hand, but can produce an Angular1 example if you want. For all it is the same deal, there is no difference.
I think the only option is to use html. API says that you can use html in text
property of button config. For example you can use something like this:
<i class="fas fa-download"></i>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With