如何删除dataTables按钮的默认按钮类? [英] How can I remove default button class of a dataTables button?
问题描述
我正在使用带按钮的数据表.我想显示成功"按钮而不是默认按钮. 我尝试过此代码
I am using Data table with Button. I want to show Success button rather default. I tried this Code
buttons: [
{
extend: "excel",
className: "btn-sm btn-success",
titleAttr: 'Export in Excel',
text: 'Excel'
}]
此代码有效,但这正在添加btn-success类,但是我想先删除btn-default类,然后添加成功类.
This code is working but this is adding btn-success class, But I want to remove the btn-default class first and then add the success class.
当前课程:"btn btn-default buttons-excel buttons-html5 btn-sm btn-success"
我想要的是:"btn buttons-excel buttons-html5 btn-sm btn-success"
推荐答案
是的,这确实很烦人.不使用引导程序也是如此,即使您声明了className
,也始终添加.dt-button
.您可以使用 init
回调修改示例类:
Yes, this can be really annoying. It is the same without using bootstrap, where .dt-button
always is added even if you declare className
. There is a init
callback you can use to modify for example classes :
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [{
extend: "excel",
className: "btn-sm btn-success",
titleAttr: 'Export in Excel',
text: 'Excel',
init: function(api, node, config) {
$(node).removeClass('btn-default')
}
}]
});
演示-> https://jsfiddle.net/m6hysypd/
demo -> https://jsfiddle.net/m6hysypd/
更新:对此已经获得了很多好评,但是正确或最佳 答案实际上是"DavidDomains"的答案,以下.使用
Update: Have received a lot of upvotes on this, but the correct or best answer is actually "DavidDomains"'s answer below. Use
buttons: {
dom: {
button: {
className: ''
}
},
buttons: [{
//here comes your button definitions
}]
}
这篇关于如何删除dataTables按钮的默认按钮类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!