What is the best way to customize the default button style for buttons in Angular Datables?

After integrating buttons into my Angular Datatables, I noticed that they have default styling, which makes them stand out from the rest of my web page (refer to the Column Visibility button in the screenshot below):

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

I attempted to use CSS to make the buttons look like the Bootstrap buttons used elsewhere on the page, but my efforts were unsuccessful. Adding my CSS values to

button.dt-button, div.dt-button, a.dt-button {}
required using !important for every style override, which didn't feel like the right approach.

Additionally, including

bower_components/datatables/media/css/buttons.bootstrap.css
in my page's <links> section did not produce the desired outcome either.

Is there a straightforward method to achieve this customization?

Answer №1

Previously, I used to eliminate any mention of the dt-button in my code. This particular element seemed to be causing all sorts of issues. It appears that dataTables introduced the dt-button as a way to style various tags into a uniform button look, which clashed with bootstrap. To ensure that the dataTables buttons matched the rest of the Bootstrap 3 layout, I decided to add bootstrap classes to the className:

.withButtons([ 
   { extend: 'pdf', 
     className: 'btn btn-sm btn-primary' 
   }  
])

I also made sure to remove any references to dt-button in the initComplete section:

.withOption('initComplete', function() {
  $('.dt-button').removeClass('dt-button')
})

This approach guarantees that the buttons appear exactly as intended in pure Bootstrap styling without any additional modifications. While I acknowledge that this may not be the most conventional method, as there should ideally exist a seamless integration between withBootstrap() and withButtons(), I personally have not found a successful combination despite utilizing different package versions obtained through CLI rather than manual configurations.

datatables.net
datatables.net-bs
datatables.net-buttons
angular-datatables

In my opinion, the .net packages are somewhat overshadowed by options such as dataTables download builder, CDN, and GitHub. They do not seem to be completely aligned in terms of functionality.

Answer №2

To make the necessary adjustments in my case, I included:

display: inline;

In the CSS of the elements on the left that are floating above. In my situation (using jQuery / Rails / Bootstrap), I was adding Buttons and facing issues with the Bootstrap theme affecting its appearance.

You can also customize the default CSS classes on the elements for better results:

https://datatables.net/reference/option/buttons.dom

For example, in CoffeeScript notation:

$ ->

  locations = $('#locations').dataTable
    dom: 'Bfrtip'
    ajax: 
      url: $('#locations').data('source')
      type: 'GET'
    order: [[ 3, 'desc' ], [ 2, 'desc' ]]
    processing: true
    serverSide: false
    responsive: false
    buttons:
      dom:
        container:
          className: 'btn-group'
        button:
          className: 'btn btn-primary btn-outline'

This modification removes the dt-buttons and dt-button classes, allowing the base Bootstrap CSS to function correctly.

<div class="btn-group">
  <a class="btn btn-primary btn-outline buttons-copy buttons-html5" tabindex="0" aria-controls="locations" href="#">
    <span>Copy</span></a>
  <a class="btn btn-primary btn-outline buttons-pdf buttons-html5" tabindex="0" aria-controls="locations" href="#">
    <span>PDF</span></a>
</div>

As a result, the Bootstrap buttons display as intended.

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

Trouble with CSS submenus: Are your lists not appearing as they should? Potential style override

I am encountering an issue with my dropdown mega menu. I have two sets of list items that should be displayed vertically side by side with bullet points in the dropdown, but only one list is appearing despite coding for both. Additionally, the list elemen ...

prevent $location.path from causing the page to reload

Despite researching this issue extensively on stackoverflow and google groups, I still can't seem to pinpoint why my app is not functioning correctly. The problem arises when I added reloadOnSearch: false, to the route, yet the page continues to r ...

Leveraging the (click) event within an HTML template to manage a [hidden] element located in a different template using Angular 2

Within my project, I have two TypeScript files, each containing HTML templates inside the @Component. In one of the templates, there are info cards that can be collapsed or expanded using [hidden]="collapsed". The following function is present in both file ...

What is the best way to update a CSS class in React JS?

Suppose I have a CSS class called 'track-your-order' in my stylesheet. Whenever a specific event occurs, I need to modify the properties of this class and apply the updated values to the same div without toggling it. The goal is to replace the ex ...

having difficulty with an intricate flexbox grid within another flexbox

I attempted to create a grid-like pattern using a negative margin based grid system (Susy) but was unsuccessful. Next, I tried employing flexbox for the task. However, I'm unsure if it's achievable. My initial idea was to have 2 columns (side A ...

Unable to transfer files, encountering issues with PHP and AngularJS integration

I am currently working on uploading files using both AngularJS and PHP. For the AngularJS part, I am utilizing angular-file-upload from https://github.com/danialfarid/angular-file-upload. I suspect that the issue lies in my PHP code, as it fails to move ...

Error encountered when parsing with Phantom JS and Angular JS: "Parse Error"

Encountering a SyntaxError: Parse error when running unit tests with Karma on PhantomJS. PhantomJS 1.9.7 (Windows 7) ERROR SyntaxError: Parse error at d:/Path/To/File/index.html.js.js.js.js:11 PhantomJS 1.9.7 (Windows 7): Executed 0 of 0 ERROR (0 ...

Tips for notifying highlighted text in Kendo Editor

How can I provide an alert for a selected text inside the kendo editor? I have attempted the code below <textarea id="editor"></textarea> <script> $("#editor").kendoEditor(); var editor = $("#editor").data("kendoEditor"); var html = edit ...

What steps can I take to stop a select box within a flex container from shrinking?

Currently working on some code that involves a flex container. Struggling to prevent fields from shrinking too much on smaller screen sizes. var crsdesc; //var for new window function popup(mylink) { if (!window.focus) return true; var href; if (t ...

Output the following by using the given format: *a* -> *a1**aabbbaa* -> *a2b3a2*

I am a beginner in JavaScript. Could you please explain how to achieve the following output? * "a" -> "a1" * "aabbbaa" -> "a2b3a2" I attempted using a hash map, but my test cases are failing. Below is the code I have writt ...

aligning two elements within a container to have equal heights

I need to position 2 divs inside a container div. Their height should always be the same, regardless of content. To achieve this, I am using absolute positioning with top and bottom set to 0. Currently, the container div #three collapses and hides the cont ...

Different option for animated side slider based on location

Whenever I click on this div, it slides out smoothly. Check out these images to get a visual of what I am aiming for: This is how the Div looks when collapsed by default https://i.stack.imgur.com/zJIsA.png Once slid out, the Div looks like this (highlig ...

Interference in the output of .innerHTML leads to disruption

I have been working on a feature to display a calculated price based on the selected quantity for each individual product. I attempted to duplicate the code and modify variable names, but encountered issues with the increase/decrease buttons triggering mul ...

Having a tough time navigating the Bootstrap upgrade from 2.x to 3.x - now my design is all out of whack

Upgrading my site to the newest version of Bootstrap has been quite the challenge. I'm noticing that despite the window size being the same, version 1 and version 2 of my site are displaying different @media sizes. What's going on? On the left i ...

Denied access to [Any Url] as it breaches the specified Content Security Policy directive and refused to connect

Struggling to retrieve data using the Login() method within a post request, but encountering an error when the URL is transferred to its destination. Error: Refused to connect to 'http://smartlearner.com/SmartLearner/UserAccount/[email prote ...

Setting up Datatables using AngularJS

I am working on a controller that organizes song rankings based on sales data. Upon initialization, the controller automatically sends an HTTP GET request to retrieve all the songs needed for display (currently set at the top 20 songs). If I ever need to a ...

Conceal the Angular alert message automatically after a specified number of seconds or when the page

I recently started working with Angular and managed to implement an alert message for password reset requests in our app: Usermodel: .service('userModel', ['$q', '$http', 'authorizedTracker', function($q, $http, au ...

Styling the nested list items with text decoration

I have a scenario where I applied text-decoration: underline; to the parent li, which is being inherited by the child li. Despite trying to remove this style from the child elements using text-decoration: none !important;, it doesn't seem to work. The ...

"Can you guide me on positioning an image logo before text by utilizing the content attribute within the style tag

I am new to coding and experimenting with HTML. I want to display an image before the text "hello html" but for some reason, it is not working. Here is the code I have tried: <head> <style> .img::before { content: url("img/smartphone.png"); ...

What exactly are AngularJS nested function variables?

I am facing the following issue: function getRate(source, $scope, e) { var dateValue = $("Date", source).text() || ""; if (!dateValue) { return null; } var da ...