Datatables failing to display Bootstrap buttons

I'm having trouble styling the export buttons in datatables with bootstrap. When I add btn btn-primary, it only adds a blue border to the button. How can I make it look like a proper bootstrap primary button?

Additionally, I'd like to add some padding to the button. Is there a way to achieve this?

This is my current code:

<table id="example"  class="table table-sm table-hover">
    <thead>
        <tr>
            <th>Date</th>
            <th>Version</th>
            <th>Count</th>
            <th>Average</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

let table = $('#example').DataTable({
    data: data,
    columns: [{
        data: 'date'
    }, {
        data: 'version'
    }, {
        data: 'count'
    }, {
        data: 'avg'
    }],
    dom: 'lBfrtip',
    buttons: [{
        extend: 'csv',
        text: 'Export',
        filename: 'Export File',
        className: 'btn btn-primary'
    }]
});

This is the current output:

https://i.sstatic.net/YOfD8.png

I want the button to resemble this image: https://i.sstatic.net/1bQO8.png and I'd also like to add some padding between the button and Show 10 entries.

Can someone guide me on how to achieve this style?

Answer №1

Check out if this solution suits your needs. To add spacing to the Export button, you have the option of utilizing Bootstrap's spacing classes

Containing styles & scripts

<!-- Including Bootstrap and JQUERY-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
$(document).ready(function() {   

    let table = $('#example').DataTable({

        columns: [{
            data: 'date'
        }, {
            data: 'version'
        }, {
            data: 'count'
        }, {
            data: 'avg'
        }],
        dom: 'lBfrtip',
        buttons: [{         
            text: 'Export',
            filename: 'Export File',
            className: 'ml-3 btn btn-primary',
            action: function ( e, dt, node, config ) {
                alert( 'Button Clicked!' );                    
            }
        }]
    }); 

}); 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to determine the number of options required for a select tag to become scrollable?

Please review these two <select> elements: <select> <option>one</option> <option>one</option> <option>one</option> <option>one</option> <option>one</option> <option&g ...

Ways to Turn Off CSS Vertical Menu Flyout Animation

I'm new to HTML Lists and trying to figure out how to disable the "Hover flyout effect" so that all sub items are listed vertically below the main item while remaining visible. Can someone please help me understand which specific CSS properties can be ...

Crashing of history.pushState when using browser's back button

I am currently developing a single page application that loads each section via ajax. The homepage is a separate page, and when you click on 'About', it redirects you to the single page app. I have been able to update the URL for each section and ...

What is your approach to converting this jQuery code to ES6 syntax?

The concept involves gathering all the links and corresponding IDs, and hiding inactive content. When a link is clicked, the associated content should be displayed. The Structure <div class="navbar"> <nav> <ul class="navTabs"> ...

The transition effects of Framer Motion do not seem to be working properly when switching between keyframe

Is there a way to create a smooth transition between two keyframe animation variants in CSS? Currently, when switching from one variant to another, the change happens instantly. How can I make it so that all properties transition smoothly? const variants = ...

Incorporating a background image into a card component using props

I attempted to add a background image to the card component through props, but the image failed to display on the card. I didn't encounter any errors, and I'm unsure what mistake I might be making. Any suggestions or alternative solutions would b ...

Tips on detecting if all images within a React component have been loaded using React hooks

I am currently developing a next js application. While I have experience with ES6, I am fairly new to react. One component in my project is being called from a useEffect fetch data function in another component. Below you will find the code for this specif ...

Reveal a segment of a picture

Is there a way to display only a section of an image using either jQuery or another JavaScript method? For example: image: [ ] [ -------- ] [ - - ] [ - part - ] [ - - ] [ -------- ] [ ...

JavaScript Arrays are not functioning properly within the Poo constructor

Attempting to insert data into a JavaScript Array within my constructor has resulted in this error message: TypeError: this.listeetudiant is undefined This is my constructor: function Cours(){ */the array causing trouble: */ this.listeetudiant=[]; */ ...

I'm having trouble getting the CSS to print properly, even after adding the media="print" attribute

Currently, I am working on creating a marksheet format with some CSS styles that need to be included in the print version as well. So far, I have been successful in achieving this goal. However, I have encountered an issue where the background color in t ...

An error occurs when using e.slice function

I am facing an issue with my kendoDropDownList that uses kendo UI and jQuery. I cannot figure out why this error is occurring. $("#drpState").kendoDropDownList({ optionLabel: "States...", delay: 10, ...

Tips for inserting columns into a table using CSS and HTML

Having trouble working with columns in the tab div? It seems to work when it's pulled out of the tab div. Can anyone advise what I might be missing? For an example code, please visit: https://www.w3schools.com/code/tryit.asp?filename=FZJ3933552IJ Cu ...

Having Trouble Changing CSS with Rails Link_to CSS ID

While following the ruby on rails guide, I came across a specific way to write link_to's with a css id: <%= link_to "About", about_path, id: "third" %> I also attempted: <%= link_to ("About", :id => "third"), about_path %> Although ...

What is the best way to maintain the standard height behavior of a fixed element?

I'm new to web development and currently working on my first website using only HTML, CSS, and JavaScript. I encountered an issue with the height of a fixed block element. When the user clicks on the "Contact us" link, a box containing contact informa ...

Expanding HTML zones to reach the bottom of the screen, while implementing top and side menus using the latest HTML5 and CSS techniques

Struggling to design a page layout with two navigation sections (top and left) similar to the example below: The light gray area represents where the main content will be displayed on each page. On the left side is the secondary navigation menu that shoul ...

Can you explain the concepts of 'theme' and 'classes'?

Currently, I am working on a web application using React. I have chosen to incorporate the latest version of Material-UI for designing the user interface. During this process, I came across the demo examples provided by Material-UI (like ) In each demo ...

Sticky position problem in the navigation bar

window.onscroll= function() {myFunction()}; var navbar = document.getElementById("navbar"); var sticky = navbar.offsetTop; function myFunction() { if (window.pageYOffset >= sticky) { navbar.classList.add("sticky") } else { ...

How much does it typically cost to implement external libraries into a project?

Here are some of the most commonly used front-end web development libraries: jquery-min.js (95.9 kB) angular.min.js (108.0 kB) bootstrap.min.css (113.5 kB) bootstrap-theme.min.css (19.8 kB) bootstrap-fonts (185.7 kB) bootstrap.min.js (35.6 kB) All in al ...

Adding an image in HTML from a different drive - step-by-step guide!

Currently, I am immersing myself in HTML, CSS, and JavaScript as I gear up for my upcoming school project centered around frontend development. Here's the issue I encountered. While attempting to insert an image into one of my HTML files, I ran into ...

jQuery can be utilized to generate repeated fields

$(document).ready(function(){ $('#more_finance').click(function(){ var add_new ='<div class="form-group finance-contact" id="finance_3"><div class="col-sm-9"><label for="firstName" class="contro ...