css attribute display: none

css attribute display: none

mBeiermBeier Posts: 4Questions: 1Answers: 0
edited February 2018 in Free community support

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)**

This discussion has been closed.