我试图在datatable的帮助下显示一些长文本,但不知何故它并没有被包装起来。这意味着,我没有得到多行文本,而是只得到了一个很长的行。当我转到我的数据库并编辑我的描述字段(字段类型是文本)时,我可以看到多行中的文本。
我已经尝试将表格的宽度设置为100%,但随后文本行一直移到表格之外。我还尝试添加了自动换行和弹性自动换行,并在我的CSS上定义了一个文本自动换行类,但同样不起作用。
你知道我该怎么解决这个问题吗?
<div style="font-size:18px;">
<table class="table-striped table-hover" id="product_table" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Group</th>
<th>Price</th>
<th>Action</th>
<th class="none">Description DE</th>
<th class="none">Description EN</th>
<th class="none">Description ES</th>
</tr>
</thead>
<tbody>
@foreach($ProductList as $product)
<tr>
<td>{{$product['ProductName']}}</td>
<td>{{$product['ProductGroupName']}}</td>
<td>{{$product['ProductListPrice']}}</td>
<td ><button class="btn btn-primary waves-effect w-md waves-light w-sm-5" data-toggle="modal" data-target="#Edit" data-id="{{$product['ProductID']}}" data-name="{{$product['ProductName']}}" data-group="{{$product['ProductGroupName']}}"
data-price="{{$product['ProductListPrice']}}" data-descde="{{$product['ProductDescriptionDE']}}" data-descen="{{$product['ProductDescriptionEN']}}" data-desces="{{$product['ProductDescriptionES']}}">Edit</button>
<td>{{$product['ProductDescriptionDE']}}</td>
<td>{{$product['ProductDescriptionEN']}}</td>
<td>{{$product['ProductDescriptionES']}}</td>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#product_table').DataTable({
columnDefs: [{
"className": "dt-center",
"targets": "_all"
}],
pageLength: 50,
responsive: true
});
});
</script>发布于 2019-04-09 18:10:08
不要紧,我发现我错了。CSS类不正确。下面是这个类应该是什么样子:
.text-wrap{
white-space:normal;
}发布于 2019-04-09 18:09:57
尝试在表中添加wrap类。
<table class="table-striped table-hover wrap" id="product_table" cellspacing="0" width="100%">https://datatables.net/forums/discussion/43760/force-datatable-to-wrap-text#Comment_115199
https://stackoverflow.com/questions/55590042
复制相似问题