How can I remove default button class of a dataTables button?

后端 未结 5 1228
名媛妹妹
名媛妹妹 2020-12-28 17:04

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


        
5条回答
  •  滥情空心
    2020-12-28 17:22

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

    demo -> https://jsfiddle.net/m6hysypd/


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

提交回复
热议问题