Bootstrap4 CSS attribute 'display: none'

Bootstrap4 CSS attribute 'display: none'

mBeiermBeier Posts: 4Questions: 1Answers: 0

Hey,

in the past I used DataTables with Bootstrap 3, actually im refractoring for Bootstrap 4.

there is a strange behaviour with DataTables and Bootstrap 4.
First it always adds a 'display: none' css property to my table div.

-> this is from my rendered page

<table id="devices" class="table display responsive dataTable no-footer" role="grid" aria-describedby="devices_info" style="width:  557px; display: none;">

if I remove the display: none property manually the table shows up but looks strange .. if I also remove the dataTable class, the table looks like a normal bootstrap 4 table, but the width is not set to 100% to the div.

if I change the 'width: xxx px' property to 100% it has its full width.

I dont actually know where my failure is.

// includes

// My Bootstrap 4 Stylesheet version
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
// Stylesheet
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.16/b-1.5.1/b-html5-1.5.1/b-print-1.5.1/r-2.2.1/sc-1.4.4/sl-1.2.5/datatables.min.css"/>

// My jQuery Version
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
// My Bootstrap Version
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
// Javascript
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>

// HTML table div

<table id="devices" class="table display responsive">
 <thead>
  <tr>
   <th>Name</th>
   <th>Serial</th>
   <th>Article</th>
   <th>Gateway</th>
  </tr>
 </thead>
</table>

// table header data

const deviceTHead =
  [
    {
      data: 'name',
    },
    {
      data: 'serial',
    },
    {
      data: 'article',
    },
    {
      data: 'gatewayId',
    },
  ];

// table body data

const devicesTdata = [];
for (let i = 0; i < expressData.customerDevices.length; i += 1) {
  devicesTdata.push({
    name: expressData.customerDevices[i].settings.name,
    serial: expressData.customerDevices[i].serial,
    article: expressData.customerDevices[i].article,
    gatewayId: expressData.customerDevices[i].settings.gatewayId,
  });
}

// data example

[…]
0: {…}
article: "0000"
gatewayId: "1234"
name: "Testname"
serial: "9876"

// dataTables

const deviceTableOpts = $('#devices').DataTable({
  // searching: false,
  // paging: false,
  responsive: true,
  columns: deviceTHead,
  data: devicesTdata,
});

**
Edit: I have the same Problem with your example Bootstrap 4 DataTable (copy&paste)**

Replies

  • mBeiermBeier Posts: 4Questions: 1Answers: 0

    Hey,

    I actually can't edit the post anymore but i have to add, when i remove the 'table' class, all data is shown, but without bootstrap css styles.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Can you link to a page showing the issue please? This example shows DataTables working with Bootstrap 4 as expected.

    Allan

  • mBeiermBeier Posts: 4Questions: 1Answers: 0

    The page is local at the moment.

    I also copy&pasted the example on my page, but there is still no table showing up, there is always the css attribute 'display: none' added to the table .. not even to any class, the attribute is only added to this element.

    Element {
        width: 100%;
        display: none;
    }
    table.dataTable {
        clear: both;
        margin-top: 6px !important;
        margin-bottom: 6px !important;
        max-width: none !important;
        border-collapse: separate !important;
    }
    .table {
        width: 100%;
        max-width: 100%;
        margin-bottom: 1rem;
        background-color: transparent;
    }
    table {
        border-collapse: collapse;
    }
    *, ::after, ::before {
        box-sizing: border-box;
    }
    html, body {
        font-family: 'Roboto', sans-serif;
        font-size: 14px;
    }
    body {
        font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
        font-size: 1rem;
        font-weight: 400;
        line-height: 1.5;
        color: #212529;
        text-align: left;
    }
    :root {
        --blue: #007bff;
        --indigo: #6610f2;
        --purple: #6f42c1;
        --pink: #e83e8c;
        --red: #dc3545;
        --orange: #fd7e14;
        --yellow: #ffc107;
        --green: #28a745;
        --teal: #20c997;
        --cyan: #17a2b8;
        --white: #fff;
        --gray: #6c757d;
        --gray-dark: #343a40;
        --primary: #007bff;
        --secondary: #6c757d;
        --success: #28a745;
        --info: #17a2b8;
        --warning: #ffc107;
        --danger: #dc3545;
        --light: #f8f9fa;
        --dark: #343a40;
        --breakpoint-xs: 0;
        --breakpoint-sm: 576px;
        --breakpoint-md: 768px;
        --breakpoint-lg: 992px;
        --breakpoint-xl: 1200px;
        --font-family-sans-serif: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
        --font-family-monospace: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
    }
    html {
        font-family: sans-serif;
        line-height: 1.15;
        -webkit-text-size-adjust: 100%;
    
  • mBeiermBeier Posts: 4Questions: 1Answers: 0

    Hey,

    wow, okay I spend so many hours trying to fix this problem.

    window.onload = function () {
                    $('.table').hide();
    };
    

    but with this script, the table can't show up.

    thanks for your help allan.

This discussion has been closed.