[英]DataTable is exceeding my modal width
Good day everyone,大家好,
Im having problem working with datatable inside a modal.我在模态内使用数据表时遇到问题。 If it has a few column it works fine but if the width of all the columns is larger than the width of he modal it goes messy.
如果它有几列,它工作正常,但如果所有列的宽度大于模态的宽度,它就会变得混乱。 please see the image
请看图片
any help will be appreciated任何帮助将不胜感激
Here is code for my table:这是我的表的代码:
<div class="modal" role="dialog" id="modalDeleveryReceiptView_SelectDeliveredBy">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">Employee Selection</h3>
</div><!--modal header-->
<div class="modal-body">
<table id="tblDeliveryReceiptView_EmployeeSelection"class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0">
<thead>
<tr>
<th>Emp #.</th>
<th>First Name</th>
<th>Middle Name</th>
<th>LastName</th>
<th>Gender></th>
<th>Job Title</th>
</tr>
</thead>
<tr>
<td>EMP-16-000001</td>
<td>Exequiel</td>
<td>Santos</td>
<td>Cuevas</td>
<td>Male</td>
<td>Dev</td>
</tr>
<tr>
<td>EMP-16-000001</td>
<td>Exequiel</td>
<td>Santos</td>
<td>Cuevas</td>
<td>Male</td>
<td>Dev</td>
</tr>
<tr>
<td>EMP-16-000001</td>
<td>Exequiel</td>
<td>Santos</td>
<td>Cuevas</td>
<td>Male</td>
<td>Dev</td>
</tr>
</table><!--Employee Selection table-->
</div><!--modal body-->
</div><!--modal content-->
</div><!--modal dialog-->
</div><!--modal Select Delivered By-->
Here is my Script:这是我的脚本:
$('#tblDeliveryReceiptView_EmployeeSelection').DataTable({
"paging": false,
"info": false,
"searching": true,
"autoWidth": false
});
I want it to become like this:我希望它变成这样:
Where the exceeding columns is placed inside a child row that will only be visible if you click the plus button
超出的列放置在子行中,只有单击加号按钮才能看到该子行
I had the same problem and this code fixed my problem.我遇到了同样的问题,这段代码解决了我的问题。
$(modal-selector).on('shown.bs.modal', function () {
var table = $('#tblDeliveryReceiptView_EmployeeSelection').DataTable({
paging: false,
info: false,
searching: true,
autoWidth: false
});
table.columns.adjust().draw();
});
You should set the property overflow-x
to auto
in <div class="modal-body">
as @monerico commented on your question, this way:您应该在
<div class="modal-body">
中将属性overflow-x
为auto
,因为@monerico 对您的问题发表了评论,这样:
overflow-x:auto;
Additionally, you may want to increase the width of the modal itself to show the complete content of the table.此外,您可能希望增加模态本身的宽度以显示表格的完整内容。
Please share your CSS for further help.请分享您的 CSS 以获得进一步的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.