table flows outside of div
table flows outside of div
montoyam
Posts: 568Questions: 136Answers: 5
I looked in the forum but I haven't seen this posted before:
I am using Bootstrap 4 and find that the DataTable will flow outside of the div. The search box and page navigations stay within the div, but not the rows of data
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<div class="card pt-3 mb-3">
<h3 class="card-title">Departments</h3>
<div class="card-body">
<table class="table table-striped table-bordered" id="Departments"></table>
</div>
</div>
</div>
DepartmentsTable = $('#Departments').DataTable({
dom: 'Bfr<"totals_FTE">tip',
ajax: 'api/Departments',
columns: [
{
title: "Fund/Org count",
className: 'details-control',
orderable: false,
data: 'DeptFundOrg', render: function (data) {
return data.length;
},
defaultContent: '',
width: '10%'
},
{ data: "Departments.DepartmentName", title: "Department" },
{ data: "dc.Group_Total_FTE", className: "dt-body-right dt-head-right", title: "Total FTE" },
{ data: "dc.Group_Total_Emp", className: "dt-body-right dt-head-right", title: "# Employees" },
{
data: 'DeptFundOrg',
title: "Fund/org",
visible: false,
render: function (data) {
return data.map(function (o) {
return o.Fund + ' ' + o.Org;
})
}
}
],
order: [[1, 'asc']],
select: { style: 'single' },
//scrollY: 300,
paging: false,
autoWidth: true,
buttons: {
buttons: [
{ extend: 'create', editor: DepartmentsEditor, text: '<span class="fa fa-plus-circle fa-2x icon-purple"></span>', className: 'btn', titleAttr: 'Add Department' },
{ extend: 'edit', editor: DepartmentsEditor, text: '<span class="fa fa-edit fa-2x icon-purple"></span>', className: 'btn', titleAttr: 'Edit Department' }
],
dom: {
button: { tag: 'i', className: '' }
}
}
});
```
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Start by adding
style="width:100%"
to thetable
tag, as shown in this example. If the data in the rows is too wide you may need to usescrollX
or the Responsive extension.Kevin
ah, yes, width:100% worked perfectly.
I tried to add it to the css so I wouldn't have to do it for each table, but it doesn't seem to be working. is this the correct syntax (I am using bootrap4 if that matters)?
The example explains this:
So you need to add it directly to the
table
element.Kevin
darn. ok. thanks.
i found i can also do this after the tables are rendered:
w-100 is a class in Bootstrap.