How can I remove default button class of Datatable (btn-default)

How can I remove default button class of Datatable (btn-default)

znadafznadaf Posts: 1Questions: 1Answers: 0

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

This code is working but this is adding btn-success class, But I want first remove the btn-default class then add the success class.

Current Classes: "btn btn-default buttons-excel buttons-html5 btn-sm btn-success"
What I want: "btn buttons-excel buttons-html5 btn-sm btn-success"

Answers

  • allanallan Posts: 63,467Questions: 1Answers: 10,466 Site admin

    Hi,

    Its being added here - and the class names are additive. So what we need to do is remove it from the defaults:

    $.fn.dataTable.Buttons.defaults.dom.button.className = 'btn';
    

    should do it.

    Allan

  • SceantiSceanti Posts: 1Questions: 0Answers: 0

    Hi Allen,

    When I do this:
    editor
    .title( '' )
    .message( "are you sure" )
    .buttons( [
    {
    "className": 'btn-link',
    label: "delete",
    fn: function () {
    cat_editor.submit();
    }
    }
    ])
    .remove( $(this).closest('tr') );

    Then the button on the popup has the class: "btn btn-default btn-link".
    This always happens, even if I do: $.fn.dataTable.Buttons.defaults.dom.button.className = 'btn';

    Is there a way that I can not have the "btn-default" class there?

    Regards,
    Marcel

  • allanallan Posts: 63,467Questions: 1Answers: 10,466 Site admin

    Hi Marcel,

    Yes - use:

    $.fn.dataTable.Editor.classes.form.button = "btn";
    

    before you initialise the Editor. That should resolve it in this case. Its Editor that is adding the btn-default class.

    Allan

This discussion has been closed.