MDBootstrap Datatable Failing to Apply Automatic Styling Properly

Working on my Laravel project, I decided to use MDBootstrap to style a datatable. However, after running the script at the bottom of my page to create the datatable, I noticed that the Search function and pagination were not styled and did not have classes added to them. Even the "Show Entries" button at the top left remained unstyled by MDB. Comparing with the example on the Bootstrap webpage, it seemed like everything should have been styled automatically with the scripts included. Is there something I might be overlooking?

        // Material Design example
        $(document).ready(function () {
            $('#dtBasicExample').DataTable({
                "order": [[ 1, "asc" ]]
            });
            $('.dataTables_length').addClass('bs-select');
        });
    </script>

index.blade.php

@extends('layouts.app')
@section('content')

    <div class="float-left">
        <a href="/" class="btn btn-light-blue">
            <i class="fa fa-arrow-left" aria-hidden="true"></i>
        </a>
    </div>
    <table id="dtBasicExample" class="table" width="100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table> 
@endsection
@section('scripts')
    <script src="{{asset('js/jquery.min.js')}}"></script>
    <script src="{{asset('js/popper.min.js')}}"></script>
    <script src="{{asset('js/bootstrap.min.js')}}"></script>
    <script src="{{asset('js/datatables2.min.js')}}"></script>
    <script>
        // Material Design example
        $(document).ready(function () {
            $('#dtBasicExample').DataTable({
                "order": [[ 1, "asc" ]]
            });
            $('.dataTables_length').addClass('bs-select');
        });
    </script>
@endsection

app.scss

// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');
@import url('https://use.fontawesome.com/releases/v5.11.2/css/all.css');

// Bootstrap
//@import '~bootstrap/scss/bootstrap';

// MDBootstrap
@import '~mdbootstrap/css/bootstrap.min.css';
@import '~mdbootstrap/css/mdb.min.css';
@import '~mdbootstrap/css/addons/datatables2.min.css';

//Awesome Font
@import '~font-awesome/css/font-awesome.min.css';

app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="{{asset('css/app.css')}}">
    <title>Datatable Test</title>

</head>
<body>
<div class="container">
    <br>
    @include('inc.messages')
    @yield('content')
</div>
<script src="{{asset('js/app.js')}}"></script>
    @yield('scripts')

</body>
</html>

bootstrap.js

window._ = require('lodash');

/**
 * Loading jQuery and Bootstrap jQuery plugin for JavaScript based Bootstrap features.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    // require('bootstrap');
    require('./../../node_modules/mdbootstrap/js/jquery.min.js');
    require('./../../node_modules/mdbootstrap/js/popper.min.js');
    require('./../../node_modules/mdbootstrap/js/bootstrap.min.js');
    require('./../../node_modules/mdbootstrap/js/mdb.min.js');
    require('./../../node_modules/mdbootstrap/js/addons/datatables2.min.js');

} catch (e) {}


window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Implementation of Echo API for subscribing to channels and listening for events broadcasted by Laravel.
 */

// import Echo from 'laravel-echo';

// window.Pusher = require('pusher-js');

// window.Echo = new Echo({
//     broadcaster: 'pusher',
//     key: process.env.MIX_PUSHER_APP_KEY,
//     cluster: process.env.MIX_PUSHER_APP_CLUSTER,
//     forceTLS: true
});

webpack.mix.js

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Using Mix for defining Webpack build steps in your Laravel application.
 | Compiling Sass file for the application and bundling JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .js('node_modules/mdbootstrap/js/jquery.min.js', 'public/js')
    .js('node_modules/mdbootstrap/js/popper.min.js', 'public/js')
    .js('node_modules/mdbootstrap/js/bootstrap.min.js', 'public/js')
    .js('node_modules/mdbootstrap/js/addons/datatables2.min.js', 'public/js');



Answer №1

It turned out that the missing piece for styling was additional scripting. By adding the following script below my existing scripts and before the DataTable function at the end of index.blade.app, I was able to achieve the desired styling.

    <!-- Datatable Scripts -->
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
    <script>

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

Changing the background color of radio buttons using Chrome and the power of WebGL<script>canvas</script>

When using the Three.js WebGL renderer, I noticed that radio buttons have white backgrounds, but this issue only seems to occur in Chrome. If you want to see the problem for yourself, check out this fiddle: http://jsfiddle.net/5pL8v/328/ Does anyone know ...

Leverage the power of Bootstrap by showcasing several carousels in a sleek grid layout

How can I display dynamically generated carousels in a grid format using Bootstrap4? Current formation: https://i.sstatic.net/H3du7.png I want to showcase multiple carousels containing one or more images in a clean grid layout instead of the current hor ...

Exploring Vue 3: Choosing between using import statements in main.js and configuring additionalData in vue.config.js to load a global scss file

I am attempting to load a global SCSS file using the "vue.config.js" file. vue.config.js module.exports = { css: { loaderOptions: { sass: { additionalData: `@import "@/assets/common.scss";` } } } } If I include the style tag in my App. ...

hasManyThrough is a powerful relationship in Laravel

Below are the three tables I have: +-----------------+ +---------------------+ +-------------+ | products | | product_countries | | countries | +-----------------+ +---------------------+ +-------------+ | id | | i ...

Are websites built with HTML and JavaScript considered secure in today's digital age?

In the scenario where I create a website using HTML5, Javascript, and CSS3 with no forms or input fields other than mouse clicks on links, as well as no logins, messaging, or comments - will this site still be vulnerable to attacks? Recently, my hosting s ...

Firefox hovers with a height of 0 effect activated

Hey there, I'm experiencing an issue in Firefox. When I attempt to use a hover effect on a div to change the height to 0, it's behaving strangely. Is there a way to make it function like it does in Chrome? Here is the code snippet: CSS : #squa ...

Can we limit the number of items to just two per row in a grid with two columns?

I'm currently facing issues with aligning items within a two-column grid. When looking at this image, you'll notice that the alignment is off. Specifically, 'Example 3' does not align properly with 'Example 4'. This seems to b ...

Adjust the size of bootstrap card titles to match up with the image on the page

I am facing an issue where the title of the second card is pushing the image down. Is there a way to dynamically resize the card title to align all the images properly? Any help would be appreciated. https://i.sstatic.net/PRRHl.png Bootstrap Card ...

Any suggestions on how to display the data names field in the vue-multiselect plugin on the edit page?

Currently, I am working on the edit page for employees on my vue laravel SPA. The create employees page is already set up and I am utilizing the vue-multiselect plugin () to display data. At present, I have managed to show the employee ID's from an ar ...

Apply a CSS class to the header cells

I'm facing a challenge with adding a CssClass to a table that is generated automatically through C#. The table creation code looks like this: TableHeaderRow header = new TableHeaderRow(); cell1 = new TableCell { Text = "Brand" }; cell2 = new TableCel ...

Hide the overlay fullscreen menu upon clicking an anchor link

I'm having trouble with Javascript, but some of you might find this easy. I found a fullscreen overlay menu on Codepen and I'm trying to figure out how to close it when clicking an anchor link. Looking for assistance with adding javascript to c ...

Develop a form table using jQuery for selecting multiple options

Here is a loop that outputs some data: foreach ($userItems_get as $item => $value) { if ($value['prefab'] == 'wearable') { echo $value['name'] . "</br>"; echo "< ...

Ways to emphasize the current tab on the site's navigation bar?

Here's my question: I have a menu with different items, and I want to make sure that the active tab is highlighted when users switch to another page. I noticed that Stack Overflow uses the following CSS: .nav { float: left; font-size: 1 ...

sliding to the right gets jammed

I am encountering a peculiar issue with Multi-page slide functionality. Whenever I attempt to switch pages, the new page gets stuck on the left before sliding out into position. Feel free to test this problem using my JSFiddle This is the JQuery code that ...

The unique GopikaTwo Gujarati font is unfortunately not compatible with Android mobile browsers and hybrid applications

I am currently trying to incorporate the custom font GopikaTwo into my hybrid application. Below is the code snippet I have added to my CSS file: @font-face { font-family: 'GopikaTwo' !important; src: url('GopikaTwo.eot') !impo ...

Ways to assign a default background shade to a webpage with a transparent background

My page has a completely transparent background achieved by using: body { background:none transparent!important; } When I display this page in a transparent iframe on another site, I can see the website's background through the page. However, if ...

Why is the CSS not correctly linked to the index.html file?

Currently, I am working on a project involving a "is it newyear page" that should provide a simple yes or no answer. While the functionality of the page is not the issue, I am facing a problem with the link placement. I have included a link inside the < ...

The error "relative error: invalid property value" occurs when setting the width and height of a parent element

I'm having trouble getting my h2 text to appear above my images when hovered over. I keep receiving an error message in Chrome Developer Tools saying that "display: relative" is not a valid property value, but I can't figure out why. I've se ...

The Jquery function for selecting a div added by an Ajax call is not functioning properly, but it works fine without the need for an

I have a unique checkbox that I created using an Ajax call. The issue I'm facing is that the jQuery to select the checked input in the second div #test_checkbox_ajax isn't working, while it works perfectly fine in the first div #test_checkbox. Cr ...

Buttons aligned evenly with textbox

Trying to construct an input box with two buttons positioned on the left and right. Presenting the current iteration of my project: The desired appearance should resemble the textbox and button layout found here: Although I've managed to achieve a s ...