如何更改“datatable”打印按钮的默认css?

时间:2016-02-15 08:15:31

标签: jquery css datatables

如何在datatable插件中更改print和excel按钮的CSS。

                    $('#order_table').DataTable({
                        dom: 'Brtip',
                        buttons: [
                             'print','excel'
                        ]
                    });
                });

2 个答案:

答案 0 :(得分:2)

每个按钮都有一个唯一的基类.buttons-print.buttons-excel.buttons-copy等等。所以你可以直接用CSS设置按钮的样式

.buttons-print {
  background-color: red;
  color: white;
}
.buttons-excel {
  background-color: blue;
  color: white;
}

演示 - >的 https://jsfiddle.net/mg28pxe2/

.btn-default替换为.btn-primary

$('.buttons-excel, .buttons-print').each(function() {
   $(this).removeClass('btn-default').addClass('btn-primary')
})

演示 - >的 https://jsfiddle.net/48rcjrw3/

答案 1 :(得分:0)

   var orderDataTable =  $('#order_table').DataTable({
                        dom: 'Brtip',
                        buttons: [
                             'print','excel'
                        ]
                    });



     var tableTools_obj = new $.fn.dataTable.TableTools(orderDataTable , {
                    "sSwfPath": "swf/copy_csv_xls_pdf.swf",
                    "aButtons": [                           
                            {
                                "sExtends": "xls",
                                "sTitle": "OrdersReport",
                                "sToolTip": "Export to Excel",
                                "sButtonClass": "btn btn-transparent btn-primary btn-toolbar", // Here you can give all the classes realated to button with custom styles.
                                "sButtonText": "<i title='Export To Excel' class='ace-icon fa fa-file-excel-o white icon-tooltip'></i>", //overriding the default icon of Datatables, Here I am using Fontawsome icons
                               // "mColumns": GetExportableColumnsIndexes(); //this is to filter out hidden or unwanted columns form being exported.
                              // Usually it requires array on indexes, I prefer to call a function with some logic handling and returning the  required indexes.
                            }
                        ]
                    });

为此,您必须添加数据表的TableTools插件。 http://www.datatables.net/release-datatables/extensions/TableTools/js/dataTables.tableTools.js

如果这有用,请告诉我。