简体   繁体   English

数据表:在按钮中的文本旁边添加图标

[英]DataTables: Add icon next to text in button

I'd like to add an icon to the left side of the text in the buttons for my DataTable, but it's not showing up so far. 我想在我的DataTable按钮的文本左侧添加一个图标,但是到目前为止还没有显示。 This is the Javascript I have for the Add button: 这是添加按钮的Javascript:

var buttons;

$.fn.dataTable.ext.buttons.add = {
            className: 'button-add',
            text: '<i class="dt-button button-add"></i> Add Branch',
            action: function (dt) {
                onBtnAddClicked()
            }
        };

And in CSS: 在CSS中:

.fn.dataTable.ext.buttons.add.button-add span{
    background: url(../img/icn_add.png) no-repeat center left;
}

I've checked here , here , and here . 我已经在这里这里这里检查 Thanks for any guidance. 感谢您的指导。

Well, that was simple. 好吧,那很简单。 Looks like all I had to do was put the img tags directly into the Text string, I didn't know that was possible. 看来我要做的就是将img标签直接放入Text字符串中,我不知道那是可能的。

$.fn.dataTable.ext.buttons.add = {
            //className: 'button-add',
            text: '<img src="../img/icn_add.png" style="padding-bottom: 2.25px; padding-right: 6px"> Add Branch',
            action: function (dt) {
                onBtnAddClicked()
            }
        };
  1. Check icn_add.png is at appropriate location 检查icn_add.png在适当的位置
  2. As 'button-add' class will be applied to anchor, Try following css - 由于“ button-add”类将应用于锚点,请尝试以下css-

    a.button-add span{ background: url(../img/icn_add.png) no-repeat center left; }

Alternatively, you can use font-awesome.css 或者,您可以使用font-awesome.css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM