Modal Button Defaults
Modal Button Defaults
            
                            
                                  in Editor             
        I want to change the default button style shown in the modals when using Editor, such as in the image below taken from the website:

So far, I have successfully changed the text of the buttons above the DataTable itself:
    $.extend(true, $.fn.dataTable.Editor.defaults, {
    i18n: {
        create: {
            button: '<i class="fa-duotone fa-solid fa-circle-plus me-2"></i>New',
            submit: '<i class="fa-duotone fa-solid fa-arrow-down-to-bracket me-2"></i>Submit'
        },
        edit: {
            button: '<i class="fa-duotone fa-solid fa-pen-to-square me-2"></i>Edit',
            submit: '<i class="fa-duotone fa-solid fa-arrow-down-to-bracket me-2"></i>Save'
        },
        remove: {
            button: '<i class="fa-duotone fa-solid fa-circle-minus me-2"></i>Delete',
            submit: '<i class="fa-duotone fa-solid fa-circle-minus me-2"></i>Delete'
        }
    }
});
And rather horrendously, the style of those buttons:
$.extend(true, $.fn.dataTable.defaults, {
    preDrawCallback: function (settings) {
        // Modify button classes
        $('.dt-buttons button').each(function () {
            let buttonText = $(this).text().trim();
            if (buttonText.includes('New')) {
                $(this).removeClass('btn-secondary').addClass('btn-falcon-primary');
            }
            if (buttonText.includes('Edit')) {
                $(this).removeClass('btn-secondary').addClass('btn-falcon-info');
            }
            if (buttonText.includes('Delete')) {
                $(this).removeClass('btn-secondary').addClass('btn-falcon-danger');
            }
        });
    }
});
How can I more efficiently change the classes of the DataTable buttons, globally, and change the classes of the Editor modal buttons?
This question has accepted answers - jump to:
Answers
Are you using Buttons to trigger the modal (e.g.
create,edit, etc)?If so, you could do:
Alternatively, you could override the defaults:
The key here is to know that
formButtonsis passed intobuttons()when the button is activated. (It also can get a little confusing that there are the top level "Buttons" buttons, and the form buttons inside the form...)Allan
Allan, amazing as always, thank you!
I just needed $.fn.dataTable.ext.buttons for my purposes.
Lastly, how can I set the default for the DataTable buttons instead of using preDrawCallback?
I can set individual tables like so and want to do so globally with defaults:
Edit
As I submitted, I tried this and solved my issue:
For those buttons you could do:
Allan