Datatables custom button appearance

Datatables custom button appearance

3ncor33ncor3 Posts: 2Questions: 1Answers: 0

Hi,

I tried to change the custom button color (based on bootstrap class) and the button tag (from <a> to <button>) but code below is not working.

I know the default button structure is like this :

<a class="dt-button">...</a>

but I want the tag to be like this :

<button>My Custom Button</button>

Here is my code but nothing happen to the button (tag not change, class also not applied).

$('#akaunTable').DataTable( {
    dom:'lBtipr',   
    buttons:[{
        text:"Register new",
        action:function(e, dt, node, config){
            //trigger the bootstrap modal               
        },
        dom:{
            button:{
                tag:"button",
                className:"btn btn-primary"
            },
            buttonLiner: {
                tag: null
            }
        }
    }]
});

Any help is appreciated. Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    The dom option should not be in the buttons array. You want to use:

    $("#akaunTable").DataTable({
      dom: "lBtipr",
      buttons: {
        buttons: [
          {
            text: "Register new",
            action: function(e, dt, node, config) {
              //trigger the bootstrap modal
            }
          }
        ],
        dom: {
          button: {
            tag: "button",
            className: "btn btn-primary"
          },
          buttonLiner: {
            tag: null
          }
        }
      }
    });
    

    Allan

  • 3ncor33ncor3 Posts: 2Questions: 1Answers: 0

    Perfect!

    Thanks Allan! ;)

This discussion has been closed.